Created
March 11, 2019 09:23
-
-
Save aliuwahab/7e1aa53a25d74b5e1ab7f72ee3216816 to your computer and use it in GitHub Desktop.
This is an example mock testing an event class in Laravel.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @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