-
Notifications
You must be signed in to change notification settings - Fork 460
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
InvalidCountException even though the mock method is called #1352
Comments
Hey @maxbethke, Thanks for reporting your findings.
It looks like the mock object is properly configured to expect the
Each time the
The equivalent Mockery code for the above code would look like this: class SchemaValidatorServiceTest extends MockeryTestCase
{
private $schemaValidatorService;
private $validatorBuilder;
protected function setUp(): void
{
$this->validatorBuilder = \Mockery::mock(ValidatorBuilder::class);
+ $this->validatorBuilder->shouldReceive('fromYaml')->once()->andReturnSelf();
$this->schemaValidatorService = new SchemaValidatorService($this->validatorBuilder);
}
public function testThatItUsesTheApiSpecification()
{
- $this->validatorBuilder->shouldReceive('fromYaml')->once()->andReturnSelf();
$this->schemaValidatorService->validateRoutedRequest();
}
protected function tearDown(): void
{
\Mockery::close();
}
} To summarize, the code you provided sets up 2 expectations for the mock object. once inside The test fails because that method is called exactly 1 time in This is the expected behavior. Let me know if this resolves the issue for you. (please don't forget to closing this issue.) |
Mockery Version
1.6.7
PHP Version
PHP 8.3
Issue Description
When testing certain method calls on a constructor-injected mock, Mockery is throwing a
Mockery\Exception\InvalidCountException
, indicating that the method wasn't called, even though it is called in the tested code. The specific method in question isfromYaml()
from theLeague\OpenAPIValidation\PSR7\ValidatorBuilder
class.Steps to Reproduce
The following code can be used to reproduce the issue:
Expected Behavior
The test should pass
Actual Behavior
Mockery\Exception\InvalidCountException : Method fromYaml(<Any Arguments>) from Mockery_1_League_OpenAPIValidation_PSR7_ValidatorBuilder should be called exactly 1 times but called 0 times.
is thown and the test failsException or Error
Mockery\Exception\InvalidCountException
Additional Information
The test passes, when I use PHPUnits
createMock
instead of mockery like thisThe text was updated successfully, but these errors were encountered: