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] Improve testability of batched jobs #44075

Merged
merged 4 commits into from
Sep 12, 2022

Conversation

jasonmccreary
Copy link
Contributor

@jasonmccreary jasonmccreary commented Sep 9, 2022

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
Copy link
Contributor Author

jasonmccreary commented Sep 9, 2022

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