Skip to content

[9.x] Improve testability of batched jobs - #44075

Merged
taylorotwell merged 4 commits into
laravel:9.xfrom
jasonmccreary:test-cancelled-jobs
Sep 12, 2022
Merged

taylorotwell merged 4 commits into
laravel:9.xfrom
jasonmccreary:test-cancelled-jobs

Conversation

@jasonmccreary

@jasonmccreary jasonmccreary commented Sep 9, 2022 •

Copy link
Copy Markdown
Contributor

This implements a number of empty interface methods relating to batched jobs making it easier to test batched jobs were dispatched, cancelled, or deleted.

Before this PR, it was not possible to test that a batched job was cancelled. For example:

Bus::fake();

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

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

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

After this PR, the test above would pass.


Submitted from 37,000ft over the Gulf of Mexico.

@jasonmccreary

jasonmccreary commented Sep 9, 2022 •

Copy link
Copy Markdown
Contributor Author

Glad to remove the fakeBatch() if you feel it's not helpful. Furthermore, is this something I should put directly on the Bus facade?

@taylorotwell
taylorotwell merged commit a155ccd into laravel:9.x Sep 12, 2022
@jasonmccreary
jasonmccreary deleted the test-cancelled-jobs branch September 12, 2022 19:09
@GrahamCampbell GrahamCampbell changed the title Improve testability of batched jobs [9.x] Improve testability of batched jobs Nov 6, 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