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

Mockery::spy gives wrong error when called with unmatched argument #1426

Open
vinaydotblog opened this issue May 23, 2024 · 0 comments
Open
Assignees
Labels
Bug An error or unexpected behavior. Feature Request request a new feature

Comments

@vinaydotblog
Copy link

Mockery Version

1.6.12

PHP Version

PHP 8.3

Issue Description

When using mock or spy with arguments I am getting a completely un-expected behaviour. If you see the steps to re-produce the given example works fine if the arguments match without any error, but gives totally different error when arguments do not match.

Steps to Reproduce

Paste this in a file and run it.

<?php

require './vendor/autoload.php';

class Builder
{
	function build()
	{

	}
}

$spy = \Mockery::spy('Builder[build]');
$spy->build(2);
$spy->shouldHaveReceived('build')->with(1);

Expected Behavior

It should display the diff between the argument expected and argument passed.

Actual Behavior

It's acting as if method was never called at all.

Method build(<Any Arguments>) from Mockery_0_Builder should be called
 at least 1 times but called 0 times.

Exception or Error

Fatal error: Uncaught Mockery\Exception\InvalidCountException: Method build(<Any Arguments>) from Mockery_0_Builder should be called
 at least 1 times but called 0 times. in ~/Herd/tinyphp/vendor/mockery/mockery/library/Mockery/CountValidator/AtLeast.php:42
Stack trace:
#0 ~/Herd/tinyphp/vendor/mockery/mockery/library/Mockery/Expectation.php(739): Mockery\CountValidator\AtLeast->validate(0)
#1 ~/Herd/tinyphp/vendor/mockery/mockery/library/Mockery/ReceivedMethodCalls.php(36): Mockery\Expectation->verify()
#2 ~/Herd/tinyphp/vendor/mockery/mockery/library/Mockery/VerificationDirector.php(86): Mockery\ReceivedMethodCalls->verify(Object(Mockery\VerificationExpectation))
#3 ~/Herd/tinyphp/vendor/mockery/mockery/library/Mockery/VerificationDirector.php(143): Mockery\VerificationDirector->verify()
#4 ~/Herd/tinyphp/vendor/mockery/mockery/library/Mockery/VerificationDirector.php(98): Mockery\VerificationDirector->cloneApplyAndVerify('with', Array)
#5 ~/Herd/tinyphp/test.php(15): Mockery\VerificationDirector->with(1)
#6 {main}
  thrown in ~/Herd/tinyphp/vendor/mockery/mockery/library/Mockery/CountValidator/AtLeast.php on line 42

Additional Information

No response

@vinaydotblog vinaydotblog added the triage needs to be triaged label May 23, 2024
@ghostwriter ghostwriter linked a pull request May 23, 2024 that will close this issue
@ghostwriter ghostwriter removed a link to a pull request May 23, 2024
@ghostwriter ghostwriter added Bug An error or unexpected behavior. Feature Request request a new feature and removed triage needs to be triaged labels May 23, 2024
@ghostwriter ghostwriter self-assigned this May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug An error or unexpected behavior. Feature Request request a new feature
Projects
None yet
Development

No branches or pull requests

2 participants