Skip to content

Instantly share code, notes, and snippets.

@aliuwahab
Last active March 11, 2019 09:27
Show Gist options
  • Save aliuwahab/11ddbd105cc54175c7f46ef932ce8215 to your computer and use it in GitHub Desktop.
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)
<?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