-
Notifications
You must be signed in to change notification settings - Fork 242
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
Fix return type error for unexpected method calls #518
base: master
Are you sure you want to change the base?
Conversation
Sorry for the late review; the code change seems fine The change of behaviour is what worries me, not sure how to handle it! Possibly we should have a shouldNotBeCalled-type expectation for all methods that aren't otherwise stubbed? In either case we should add some tests that capture the new behaviour explicitly |
no prob @ciaranmcnulty
Hmm interesting idea... I will probably have some time to play with this over the weekend, then I will get back to you. :) |
This seems to me a broken solution: in the third example, there is no behaviour defined for I think that we're battling the same issue from different angles (I was getting into it with #508 + #509): stubs and spies can have undefined behavior, but that was defined in Prophecy long before PHP got return types. Now that we have them, returning |
yep currently that is case, but it is changed in this PR, so prophecy returns an int instead of null to avoid the type error |
but it returns a generated value that might still break the following code if it does not match other invariants of the code. |
I'd appreciate any comments on #528 as a way forward |
Problem
This PR attempts to fix the issue of triggering a type error when an unexpected method call happens. Now it will return the correct type and let the code execution finish, so the predictions can be evaluated at the end of the test run.
See related comment here: #441 (comment)
PR which introduced the issue: #441
Relevant GitHub issues:
Example - Classes to test
Example - spec 1
The test passes: The only expectation we have is that method
bbb
should have been called with 26 and that happened so everything is fine.Note: This works with using
shouldBeCalled
beforedoStuff
as well.Example - spec 2
The test fails: The only expectation we have is that method
bbb
should NOT have been called with 26 and that happened so the test fails. (This also works using Argument::any() in the prediction)Note: This works with using
shouldNotBeCalled
beforedoStuff
as well.Example - spec 3
The test passes: There are no expectations so there is nothing that could fail here. So now the call to the method
bbb
is completely ignored, still not reported as an unexpected call. I am not sure if this is the desired behavior 🤔 since this basically eliminates the unexpected method call errors entirely. You will only see errors if you have a failed expectation.