JosephSilber / bouncer

Laravel Eloquent roles and abilities.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

scope is not reset between tests

comhon-project opened this issue · 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)

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

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

@JosephSilber is there any news about this issue ?

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?