I'm using the package spatie/laravel-sluggable in my project. I need to assert that an event was dispatched. The problem is when I fake the event (Event::fake([AdvertPublished::class])
) in the test, in theory only my Advertpublished event should be faked, but it seems the pacakge events are also faked and the method that creates the slug generateSlugOnCreate
is never executed what results in a sql error because my slug field can't be null.
Event::fake([AdvertPublished::class]);
$response = $this->json('POST', '/company/adverts', ['foo' => 'bar'])
->assertStatus(201);
$advert = Advert::first();
Event::assertDispatched(AdvertPublished::class, function ($e) use ($advert) {
return $e->advert->id === $advert->id;
});
Some one knows if I'm missing something or what can be the problem?