Skip to content
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

False error on atMost(...) invocation rule without call #4950

Closed
T-bond opened this issue Apr 6, 2022 · 0 comments
Closed

False error on atMost(...) invocation rule without call #4950

T-bond opened this issue Apr 6, 2022 · 0 comments
Labels
feature/test-doubles Stubs and Mock Objects type/bug Something is broken

Comments

@T-bond
Copy link
Contributor

T-bond commented Apr 6, 2022

Q A
PHPUnit version 9.5.20 & 8.5.26
PHP version 8.1.4
Installation Method PHAR

Summary

When using the atMost(...) invocation rule, and the UUT does not invoke the mocked function, then I get the following error:

Expectation failed for method name is "mockedMethodName" when invoked at most 1 times.
Mocked method does not exist.

Current behavior

Test fails with error, when mocked method never called with atMost(...) invocation rule.

How to reproduce

  1. Mock a class.
  2. Make an invocation rule with atMost(1) for example, but do not call the mocked method from the tested unit.
  3. Run the test.

My example call:

$this->storesRepository->expects(self::atMost(1))
  ->method('findOneBy')
  ->with(['name' => $storeName])
  ->willReturn($storeEntityWithSameName);

Expected behavior

Test passes as zero calls is smaller then the value passed to the atMost(...) invocation rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-doubles Stubs and Mock Objects type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants