#1426·mockery

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

Author: vinaydotblogCreated May 23, 2024Updated May 23, 2024
LabelsBugFeature Request

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
<?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