Feat: Adds faking ability to facade#538
Merged
freekmurze merged 5 commits intospatie:mainfrom Apr 28, 2025
Merged
Conversation
Member
|
The tests seem to fail, feel free to drop older Laravel / PHP versions |
Contributor
Author
|
I will work on that. |
…d updated corresponding tests accordingly.
Contributor
Author
|
@freekmurze, I figured what was causing issues was illuminate's Fake interface, so I just removed the dependency on it entirely as it was only there for testing and changed the corresponding assertions. I also updated the fake classes argument to be more general (mixed) as opposed to what it was before (array/collection), and then set the default to a collection. I did not bother dropping the versions as you suggested, I believe this will work, instead I can just create a new PR specifically for that if you would still want it done. |
Member
|
Thanks! |
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.
This PR adds the ability to fake internal method calls in the package from other projects.
Before
In a project using the package, it is hard to fake what the package does, which means project tests will be slow because they will have to rely on network calls which will have to hit the actual google servers. Its even harder on CI environments as you have to setup credentials for that too.
After
This PR introduces a
fakemethod on theAnalyticsfacade, the fake method swaps the actualAnalyticsclass with a fake class. The fake class uses the__callmagic method to intercept all method calls intended for the actualAnalyticsinstance.The
fakemethod also allows for an optional argument to be passed that will be returned whenever an interception has been made.Usage example:
With an expected result:
Further Improvements
As of now, during the interception, it just spits out what it gets, if this sounds like something you would allow to have in the package then I would have to complete the PR by making it so that its smarter about what it returns, specifically in regards to the relationship between the method called and the result to return.