-
Notifications
You must be signed in to change notification settings - Fork 464
Mock demeter chains and fluent interface methods with static return type
#1474
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
Conversation
Changed the PHP requirement from '>=7.3|>=8.0' back to '>=7.3'. Signed-off-by: Nathanael Esayeas <[email protected]>
Simplifies and clarifies the logic for creating and retrieving Demeter mocks, improving type annotations and removing the private noMoreElementsInChain helper. Signed-off-by: Nathanael Esayeas <[email protected]>
Moved and updated the test for Demeter chains on interface subjects to require PHP >=8.0 and assert instance type instead of null. Removed the old version of the test. Signed-off-by: Nathanael Esayeas <[email protected]>
Signed-off-by: Nathanael Esayeas <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 1.6.x #1474 +/- ##
============================================
- Coverage 78.41% 78.30% -0.11%
+ Complexity 1042 1040 -2
============================================
Files 76 76
Lines 2622 2623 +1
============================================
- Hits 2056 2054 -2
- Misses 566 569 +3 ☔ View full report in Codecov by Sentry. |
static return type
|
Hey @kirkbushell, Thank you for your contribution. I appreciate the time you invested in preparing this pull request. I was able to address the issue with a few additional commits. Syntax:
|
static return typestatic return type
As per the title, this isn't a solution to #1447 but instead illustrates the bug with a new test case.
We use the static return type for interfaces, as self can result in child classes not being able to work with said interface.
In short, if you have an interface method signature which has a static return type, mockery fails:
The test case added shows this aspect failing. I've tried solving this but honestly, I am struggling to follow the mockery code, so any guidance would be appreciated and I'll update this PR to solve the problem appropriately.
Note that this can still be done with a hacky utility method we wrote as a wrapper to help us still use demeter chain expectations on interfaces:
And it can also be done using array expectations:
So it seems to me that something funky is going on specifically with interfaces deeper down in the mockery code. Ideally, we want to be able to support demeter chain mocks on interface methods with static return types.