Expectation not counting mocked methods #5919
Labels
feature/test-doubles
Test Stubs and Mock Objects
type/bug
Something is broken
version/9
Something affects PHPUnit 9
version/10
Something affects PHPUnit 10
version/11
Something affects PHPUnit 11
Summary
Expectation of the number of calls for mocked methods is not correct
Current behavior
When setting up expectations on mocked methods on mocks, the call number is always 0.
How to reproduce
I've created a public repo that can be installed using composer: https://github.com/dingo-d/phpunit-expectation-count-issue.
On versions 9 and 10 (I know 9 is out of bugfix support, but that was the one I tested on first) I got the same error:
On version 11 I got a different error:
So I'm not sure what is the problem here.
Expected behavior
When I used xDebug to inspect the code when I ran the test, I could see that when I passed the mocked method as a dependency to the class under test, the mocked services were provided (
$cMock
and$bMock
) so their mocked methods are used and called instead of the actual classes.So I expect (no pun intended) that the call count to these methods I mocked will increase, and I'll get the info that the methods were called once for each service class.
This is just a POC from another project that has a similar structure, but the call count is different in each service, and this happens there as well (the reported count is 0 when it shouldn't be). As to why I'm doing these mocks, this is a simplified version, in my version the mocked method on the services does an API call, so I need to avoid doing that in my tests ofc (hence mocking this).
I'm not sure if I'm doing something wrong with the expectations, or if this is some edge-case bug 🤷🏼♂️
The text was updated successfully, but these errors were encountered: