Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add helper to dispatch fake job batches #44176

Merged
merged 2 commits into from
Sep 21, 2022

Conversation

jasonmccreary
Copy link
Contributor

@jasonmccreary jasonmccreary commented Sep 16, 2022

This adds a helper method to the BusFake for quickly dispatching a fake job batch with no jobs for testing purpose. It's similar to the new Job helper added in #44104, but when you want to test a batch independently.

Before:

Bus::fake();

$batch = Bus::batch([])->dispatch();
Cache::put('batched-automation', $batch->id);

Shift::runAutomation('v9.31.0'); // cancels previous batched job

Bus::assertDispatched(UpdateRepositories::class);
$this->assertTrue($batch->cancelled());

After

Bus::fake();

$batch = Bus::dispatchFakeBatch();
// ...

For convenience of testing, you may optionally pass the name of the batch. If your test requires more detail, you may continue to create and dispatch a batch with the longhand methods.

@nunomaduro nunomaduro changed the title Add helper to dispatch fake job batches [9.x] Add helper to dispatch fake job batches Sep 17, 2022
@taylorotwell taylorotwell merged commit e47cff9 into laravel:9.x Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants