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.
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
[10.x] Facade Fake Awareness #46188
[10.x] Facade Fake Awareness #46188
Changes from 4 commits
9f615f5
f2490f3
1999073
310ae09
d39e3c2
4b40621
b84ff7b
6ae1d1d
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this test changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taylorotwell because of the changes made here:
Previously, this test:
BusFake
with a$dispatcher
property of the previous facade root (\Illuminate\Bus\Dispatcher
) – Line 42BusFake
instance, now with a$dispatcher
property of the previousBusFake
instance resolved viastatic::getFacadeRoot()
(effectively making it a "nested" instance) – Line 51.As a result of the fix, calling
Bus::fake()
twice in the same test now causesBus::assertNotDispatched(...)
to fail, which is correct, as we're now using the same\Illuminate\Contracts\Bus\QueueingDispatcher
instance for theBusFake::$dispatcher
property.This test is now correct because we are now correctly verifying that the unique job was dispatched exactly once on the underlying
BusFake
instance, rather than it actually being executed twice on two separateBusFake
instances.Generally, I would say that calling
Facade::fake()
twice in the same test is an incorrect use of that feature.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry - I can't merge this with this test change. I don't understand this test anymore and we've had too many breaking changes lately.
The test used to plainly read that a unique job was dispatched and a lock acquired, then a second job couldn't be dispatched since a lock was in place for the unique job. The test no longer reads that way and is confusing. Please feel free to mark this as ready for review again when the test reads more plainly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes more sense if you disregard the "faked" element to this test. This test has been updated to reflect the REAL functionality of the
Bus
facade and underlying manager regardless of the call toBus::fake()
.In userland, you're not going to call
Bus::fake()
, so if you calledUniqueTestJob::dispatch()
twice in userland, like the test, then the the expectation is that this job was not dispatched more than once.This PR identifies a problem with using
Bus::getFacadeRoot()
and passing the result toBusFake
– callingBus::fake()
twice means you end up with the secondBusFake
instance deferring to the firstBusFake
instance rather than the underlyingDispatcher
instance (which is what it should do). In any case, callingBus::fake()
(or any Facade::fake()) more than once in a test should be considered bad practice as it leads to incorrect behaviour where
getFacadeRoot` is concerned.If it helps readability, I can add an
assertDispatchedOnce
method to theBusFake
class and update the test accordingly.