Skip to content

Instantly share code, notes, and snippets.

@aliuwahab
Created March 11, 2019 09:23
Show Gist options
  • Save aliuwahab/7e1aa53a25d74b5e1ab7f72ee3216816 to your computer and use it in GitHub Desktop.
Save aliuwahab/7e1aa53a25d74b5e1ab7f72ee3216816 to your computer and use it in GitHub Desktop.
This is an example mock testing an event class in Laravel.
/** @test */
public function test_event_mocking()
{
Event::fake();
// Perform order shipping...
Event::assertDispatched(OrderShipped::class, function ($e) use ($order) {
return $e->order->id === $order->id;
});
// Assert an event was dispatched twice...
Event::assertDispatched(OrderShipped::class, 2);
// Assert an event was not dispatched...
Event::assertNotDispatched(OrderFailedToShip::class);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment