[9.x] Allow to define which jobs should be actually dispatched when using Bus::fake#44106
Merged
taylorotwell merged 5 commits intoSep 13, 2022
Conversation
# Conflicts: # src/Illuminate/Support/Testing/Fakes/BusFake.php
Bus::fake
Contributor
|
Perhaps it would be clearer to chain Bus::fake()->except(MyJob::class) |
Contributor
Author
|
@dwightwatson I liked it, just updated the PR |
Contributor
|
I have it on my list to do this for the |
Contributor
Author
|
@jasonmccreary I'm waiting for Taylor to review this PR before implementing it on other fake classes, so I don't waste time if it gets rejected. But yeah, I agree with you 🙂 |
Contributor
|
@mateusjunges, I'll take it off my list then. 😉 |
Contributor
Author
|
I'm opening a follow up PR to implement this feature in other fake classes as well. |
Contributor
|
@jasonmccreary, yay! Please at me for the |
Contributor
Author
|
Hey @jasonmccreary you can check it out here #44117 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 problem
Currently, we can use the
Bus@fakemethod to determine which jobs should be faked when executing tests.The problem with it is that if I have 100 jobs that will be dispatched during one request and I want only one of them to be actually executed, then I have to explicit define which 99 jobs should be faked, instead of just defining which job should be dispatched.
Solution
This PR adds the option to determine which jobs should be executed when using
Bus::fake, like this example:Now, all jobs dispatched in the test case except the
MyJob::class, in the first example, orMyJob::classandAnotherJob::classin the second one, will be faked.If this PR gets merged, I can open another one adding this functionality to the
QueueandEventclasses. I can also add it to this PR if Taylor think that is that way to go.