Closed
Description
- Laravel Version: 5.7.25
- PHP Version: 7.2.9
Description:
Per the docs, no listeners should be executed after running Event::fake()
.
The auth guard is not informed that Illuminate\Support\Testing\Fakes\EventFake
should be used for dispatching events.
When I call Auth::login($user)
, it is dispatching Illuminate\Auth\Events\Login
to the real event dispatcher & my listener is being executed.
Steps To Reproduce:
Succinctly:
>>> Event::fake()
=> null
>>> Auth::guard()->getDispatcher()
=> Illuminate\Events\Dispatcher {#25}
Workaround:
In a test that I don't want to have my listeners executed:
<?php
namespace Tests;
use Tests\TestCase;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Event;
class FooTest extends TestCase
{
public function test_login_flow()
{
Event::fake();
Auth::guard()->setDispatcher(app('events'));
// . . .
}
}