I'm going to write some tests for my laravel 7 controller methods (endpoints) to be sure that they fire model observer event (for example saved
event on Product
model)
as you now model observer events do not fire while using mass update and it's possible my teammates use a mass update (by mistake), then any event does not fire and it breaks the remaining processes
So by these tests, I can be sure that all parts that rely on model observer events work currently.
In laravel testing document mentioned that if you want to assert an event has been dispatched use this code (for example):
public function testOrderShipping()
{
Event::fake();
$order = factory(Order::class)->create();
// Assert an event was dispatched
Event::assertDispatched(OrderCreated::class);
}
Is it possible to assert model observer's event has been fired (dispatched) too?