-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
Merged
Merged
[10.x] Facade Fake Awareness #46188
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9f615f5
Don't fake facades if they've already been faked
joelbutcher f2490f3
Fix auto-imported FQNs
joelbutcher 1999073
Remove unused param
joelbutcher 310ae09
fix test
joelbutcher d39e3c2
Update src/Illuminate/Support/Facades/Facade.php
joelbutcher 4b40621
Update src/Illuminate/Support/Facades/Queue.php
joelbutcher b84ff7b
Update src/Illuminate/Support/Facades/Facade.php
driesvints 6ae1d1d
Update Facade.php
taylorotwell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Illuminate\Support\Testing\Fakes; | ||
|
||
interface Fake | ||
{ | ||
// | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
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.