Courses

Advanced Laravel Testing

Testing Events with Event::fake()

Previous: Testing Emails with Mail::fake() and Notification::fake()
avatar

Hi Povilas,

I would suggest to add check for listener is attached to expected event in this lessons something like:

    /**
     * Be sure that listener attached to expected event
     * @test
     */
    public function it_has_listener_attached_to_an_event(): void
    {
        Event::fake();
        Event::assertListening(
            EventClass::class,
            ListenerClass::class
        );
    }

Best Regards

👍 6
avatar
You can use Markdown
avatar

this was remove from laravel 10 documentation. Someone know why please ?

  • Laravel 9 : https://laravel.com/docs/9.x/mocking#event-fake
  • Laravel 10 : https://laravel.com/docs/10.x/mocking
avatar

Hoooo it was moved to event page : https://laravel.com/docs/10.x/events#testing

avatar
You can use Markdown
avatar
You can use Markdown