Reputation: 394
My code:
public function testApiClient()
{
$mock = createMockApiClient();
dump($mock->someMethod());
}
protected function createMockApiClient()
{
$mockApiClient = $this->createMock(ApiClient::class);
return $mockApiClient
->expects($this->any())
->method('someMethod')
->will($this->returnValue('someString'))
;
}
So I have this error:
Error: Call to undefined method
PHPUnit_Framework_MockObject_Builder_InvocationMocker::someMethod()
I'm new in PHPUnit tests, so what to do? I can't understand why I do as wrote in example and no result - just error?
Upvotes: 0
Views: 560
Reputation: 394
So I started searching in google. Strange: no one answer. Searching on PHPUnit Github repository didn't get any solution or even tips how to solve problem.
After many different tries I !found! that method will
return PHPUnit_Framework_MockObject_Builder_InvocationMocker
class, and if I just write after will
semicolon and then return $mockApiClient
it returns Mock_ApiClient_anyHash
!
So you have to finish build your mock and only then return it.
Upvotes: 2