-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
More than one invocation handler has been configured triggered on a valid test case #4291
Comments
UPD: it was not meant to be reported as a bug. It's more of a support question. |
CC @jaapio |
Hi @morozov, What you probably didn't notice in this test is that you are creating 3 invoke mocks. 1 and 2 are called once. number 3 is called twice as you would expect. However if the latter would give you a return value that you expect things are getting unreliable. That's why the warning was introduced. In the linked test there is also a check on the arguments. which makes this situation even worse in combination with return types. The best solution I know ATM is use
In your example, the call to I do need to check if this is also the case for the linked doctrine test. Which seems a bit more complicated. I might have overlooked a scenario. However, I doubt if this is really testing what you are expecting it to test. Which was not the case in the example you gave. I will come back to you when I found out more. |
@sebastianbergmann It seems that I overlooked a scenario :-( which makes my patch completely invalid for this scenario. When I created the patch I didn't realize that there was a stranger The code below works with phpunit 9.1 but doesn't with the PR I submitted.
This is a BC break. Which was undetected until now. At first, it looked like a quick win to make the mocks more reliable. If I had more time I would suggest deprecating the Besides that, I would like to make a statement to the users of Long story short, we should revert the patch of #4258 or accept this BC break. |
Thank you for the proposed workaround and the research you've done, @jaapio! Personally, I share the sentiment about the riskiness and sometimes the questionable value of using |
@jaapio Can you send a pull request against |
@jaapio Nevermind, you're busy, I'll take care of this. |
Thanks guys for the great work. Could you please give me some insights on how to replace this matcher at()? thanks |
@nathanphan you can make it that way:
|
Summary
There is an existing test that enforces that the class will call a specific method at certain moments but not more than the expected number of times (ref). This is implemented via a combination of
self::at()
andself::exactly()
.As of #4258, PHPUnit warns about having more than one matcher for a given method invocation.
How to reproduce
The question
What is the proper way to ensure that the method is called at certain positions and the exact number of times? Removing the
self::exactly()
clause will make it possible to call$mock->test()
for the third time which would violate the contract but will not fail the test.The text was updated successfully, but these errors were encountered: