I have a mockup of a service class.
It's defined like this in my setUp
function
$this->myServiceMockup = $this->getMockBuilder(MyService::class)
->disableOriginalConstructor()
->setMethods(['myMethod'])
->getMock();
In my test function i set an expectation for it like this.
$this->myServiceMockup->expects($this->once())
->method('myMethod')
->with($this->exactly(1), 'myName')
->willReturn($this->exactly(1));
So what this means is that when i should trigger the myMethod function only once and that it will return integer 1.
So method that I'm testing has that line of code.
$myIntValue = $this->myService->myMethod($number, $name);
After this line $myIntValue
when i run the test should be 1 and test should continue, well that's my understanding on this.
But instead I get this error
Expectation failed for method name is equal to when invoked 1 time(s) Parameter 0 for invocation
My\Path\To\Class\MyService::myMethod(1, 'myName') does not match expected value.
1 does not match expected type "object".
Doesn't make any sense since myMethod
is expecting an integer and a string.
public function myMethod($number, $name)
{
return $this->table->save($number, $name);
}
Can somebody explain to me what am I doing wrong here, because I'm out of ideas.