Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scope is not reset between tests #643

Open
comhon-project opened this issue Dec 11, 2023 · 4 comments
Open

scope is not reset between tests #643

comhon-project opened this issue Dec 11, 2023 · 4 comments

Comments

@comhon-project
Copy link

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 comhon-project changed the title scope is not reset between tests (using laravel) scope is not reset between tests Dec 11, 2023
@JosephSilber
Copy link
Owner

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

@comhon-project
Copy link
Author

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

@comhon-project
Copy link
Author

@JosephSilber is there any news about this issue ?

@EriBloo
Copy link

EriBloo commented May 20, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants