[11.x] Enhance testability of batched jobs #53634
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current approach to testing batched jobs, as shown below, is somewhat unconventional:
This pull request introduces some helper functions to enhance the testability of batched jobs. Inspired by fluent JSON testing, these methods provide a more streamlined and readable approach to testing job batches within the Laravel application. The goal is to improve developer experience by offering clear, concise methods with illustrative examples.
Example Usage
has
Assert that the batch contains a job of the given type. You can also pass an integer to assert that the batch contains the exact number of jobs.
Example:
missing
Assert that the batch does not contain a job of the given type.
Example:
hasAll
Assert that the batch contains all of the given jobs.
Example:
missingAll
Assert that the batch does not contain any of the given jobs.
Example:
hasAny
Assert that the batch contains any of the given jobs.
Example:
first
Assert that the first job in the batch matches the given callback.
Example:
nth
Assert that the nth job in the batch matches the given callback or type and parameters.
Example:
equal
Assert that the batch contains exactly the given jobs with the specified parameters.
Example:
etc
Assert that the batch has unexpected jobs beyond those checked.
Example: