Hello,
I have an observer in which I send the InfrastructureUpdated event (event dispatched to all users via a websocket --- I listen to this event in the VueJS frontend ---).
public function updated(Infrastructure $infrastructure): void
{
$users = User::all();
foreach ($users as $user) {
InfrastructureUpdated::dispatch($infrastructure, $user);
}
}
I have written this test but it fails.
/** @test */
public function infrastructure_updated_event_is_triggered(): void
{
Event::fake();
User::factory()->count(5)->create();
$infrastructure = Infrastructure::factory()->create();
$infrastructure->update(['name' => 'another name']);
Event::assertDispatched(InfrastructureUpdated::class);
}
I specify that the observer is registered directly inside the model.
#[ObservedBy([InfrastructureObserver::class])]
class Infrastructure extends Model
Have you any idea why it fails ?
Thanks for your help.
V