bouncer icon indicating copy to clipboard operation
bouncer copied to clipboard

scope is not reset between tests

Open comhon-project opened this issue 1 year ago • 5 comments

Hello team!

the Scope is persistent between several application initialization (typically during tests). the scope is defined as a static value in Silber\Bouncer\Database\Models and is not reset when bouncer service is initialized. Due to this, the scope is not reset between tests.

I guess it should be reset during Silber\Bouncer\Bouncer singleton instantiation.

(using Bouncer v1.0.1)

comhon-project avatar Dec 11 '23 11:12 comhon-project

Are you setting the scope in your test code, or are you testing code that sets the scope in userland code?

JosephSilber avatar Dec 12 '23 21:12 JosephSilber

@JosephSilber , I'm testing my API, the scope is set in a middleware of the API.

comhon-project avatar Jan 03 '24 11:01 comhon-project

@JosephSilber is there any news about this issue ?

comhon-project avatar Mar 07 '24 15:03 comhon-project

Changing:

    protected function registerBouncer()
    {
        $this->app->singleton(Bouncer::class, function ($app) {
            return Bouncer::make()
                ->withClipboard(new CachedClipboard(new ArrayStore))
                ->withGate($app->make(Gate::class))
                ->create();
        });
    }

to:

    protected function registerBouncer()
    {
        $this->app->scoped(Bouncer::class, function ($app) {
            return Bouncer::make()
                ->withClipboard(new CachedClipboard(new ArrayStore))
                ->withGate($app->make(Gate::class))
                ->create();
        });
    }

in BouncerServiceProvider could fix this issue. Are you able to verify this?

EriBloo avatar May 20 '24 14:05 EriBloo

@EriBloo thanks for your answer. but it doesn't solve the problem, even if the bouncer service is instantiated again, the scope is not reset. the scope is defined statically in Silber\Bouncer\Database\Models and there is no mechanism to reset it when instantiating new Bouncer service.

comhon-project avatar Jun 10 '24 15:06 comhon-project