-
Notifications
You must be signed in to change notification settings - Fork 11k
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] Allow to define which jobs should be actually dispatched when using Bus::fake
#44106
[9.x] Allow to define which jobs should be actually dispatched when using Bus::fake
#44106
Conversation
# Conflicts: # src/Illuminate/Support/Testing/Fakes/BusFake.php
Bus::fake
Perhaps it would be clearer to chain Bus::fake()->except(MyJob::class) |
@dwightwatson I liked it, just updated the PR |
I have it on my list to do this for the |
@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 🙂 |
@mateusjunges, I'll take it off my list then. 😉 |
I'm opening a follow up PR to implement this feature in other fake classes as well. |
@jasonmccreary, yay! Please at me for the |
Hey @jasonmccreary you can check it out here #44117 |
The problem
Currently, we can use the
Bus@fake
method 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::class
andAnotherJob::class
in the second one, will be faked.If this PR gets merged, I can open another one adding this functionality to the
Queue
andEvent
classes. I can also add it to this PR if Taylor think that is that way to go.