Skip to content

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

Merged
taylorotwell merged 2 commits into
laravel:9.xfrom
jasonmccreary:batch-helper
Sep 21, 2022
Merged

taylorotwell merged 2 commits into
laravel:9.xfrom
jasonmccreary:batch-helper

Conversation

@jasonmccreary

@jasonmccreary jasonmccreary commented Sep 16, 2022 •

Copy link
Copy Markdown
Contributor

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