Last active
March 11, 2019 09:27
-
-
Save aliuwahab/11ddbd105cc54175c7f46ef932ce8215 to your computer and use it in GitHub Desktop.
This is just an example test to mock an event class like OrderShipped (not created)
This file contains hidden or 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
<?php | |
namespace Tests\Feature; | |
use App\Jobs\ExampleJob; | |
use App\User; | |
use Illuminate\Support\Facades\Bus; | |
use Tests\TestCase; | |
use Illuminate\Foundation\Testing\RefreshDatabase; | |
class ExampleTest extends TestCase | |
{ | |
use RefreshDatabase; | |
/** @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