Skip to content

Commit

Permalink
[8.x] chore(mocking): added missing bus assertion examples (#7534)
Browse files Browse the repository at this point in the history
* chore(database seeder test): Add an example to run array of specific seeders

* Update database-testing.md

* [8.x] chore(mocking): added missing bus assertion examples

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
dammy001 and taylorotwell authored Dec 27, 2021
1 parent 666ae6d commit efc061a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion mocking.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,24 @@ You may use the `Bus` facade's `fake` method to prevent jobs from being dispatch
// Assert a job was not dispatched...
Bus::assertNotDispatched(AnotherJob::class);

// Assert that a job was dispatched synchronously...
Bus::assertDispatchedSync(AnotherJob::class);

// Assert that a job was not dipatched synchronously...
Bus::assertNotDispatchedSync(AnotherJob::class);

// Assert that a job was dispatched after the response was sent...
Bus::assertDispatchedAfterResponse(AnotherJob::class);

// Assert a job was not dispatched after response was sent...
Bus::assertNotDispatchedAfterResponse(AnotherJob::class);

// Assert no jobs were dispatched...
Bus::assertNothingDispatched();
}
}

You may pass a closure to the `assertDispatched` or `assertNotDispatched` methods in order to assert that a job was dispatched that passes a given "truth test". If at least one job was dispatched that passes the given truth test then the assertion will be successful. For example, you may wish to assert that a job was dispatched for a specific order:
You may pass a closure to the available methods in order to assert that a job was dispatched that passes a given "truth test". If at least one job was dispatched that passes the given truth test then the assertion will be successful. For example, you may wish to assert that a job was dispatched for a specific order:

Bus::assertDispatched(function (ShipOrder $job) use ($order) {
return $job->order->id === $order->id;
Expand Down

0 comments on commit efc061a

Please sign in to comment.