Skip to content

Commit

Permalink
clear resolved facades earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell authored and driesvints committed Apr 24, 2020
1 parent d0afa58 commit f2ea1a2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Foundation/Testing/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ abstract public function createApplication();
*/
protected function setUp(): void
{
Facade::clearResolvedInstances();

if (! $this->app) {
$this->refreshApplication();
}
Expand All @@ -85,8 +87,6 @@ protected function setUp(): void
$callback();
}

Facade::clearResolvedInstances();

Model::setEventDispatcher($this->app['events']);

$this->setUpHasRun = true;
Expand Down

1 comment on commit f2ea1a2

@simonschaufi
Copy link

@simonschaufi simonschaufi commented on f2ea1a2 May 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@driesvints @taylorotwell I just updated to 6.x and this commit broke my tests.

I have mocked the \Illuminate\Contracts\Auth\Access\Gate with Laravel 5.8. Now with 6.x I'm getting the real \Illuminate\Auth\Access\Gate implementation when I call \Illuminate\Support\Facades\Gate::allows('foo'). What was the reason why you changed it? The commit message is not really clear what is the intention.

protected function setUp(): void
{
    parent::setUp();

    $this->mock(\Illuminate\Contracts\Auth\Access\Gate::class, static function ($mock) {
        $mock->shouldReceive('authorize')
            ->andReturnTrue();
        $mock->shouldReceive('allows')
            ->andReturnTrue();
    });
}

My workaround now is to explicitly unset the resolved Instance with Facade::clearResolvedInstance(\Illuminate\Contracts\Auth\Access\Gate::class); to always get the mock again.

Please sign in to comment.