Closed aik099 closed 3 months ago
The error message does not say that mocking such methods is not supported. It says that guessing a return value is not supported and you need to configure an explicit one (for instance by using ->willReturnSelf()
)
The error message does not say that mocking such methods is not supported. It says that guessing a return value is not supported and you need to configure an explicit one (for instance by using
->willReturnSelf()
)
That helped. Thanks.
What about the associated PR ( https://github.com/phpspec/prophecy/pull/621 ) to improve guessing code?
I'm getting an error, that willReturnSelf
method isn't defined in the used Prophecy version. I've used this code instead:
$mock = $this->prophesize('Process');
$mock->mustRun()->willReturn($mock)->shouldBeCalled();
is this correct way or I should be doing
$mock = $this->prophesize('Process');
$mock->mustRun()->willReturn($mock->reveal())->shouldBeCalled();
instead?
ah indeed. We don't have willReturnSelf
in Prophecy (maybe I confused with PHPUnit mock or with a past discussion on Prophecy that has not been implemented).
The first code snippet is fine. ->willReturn
does not require revealing explicitly.
Great. Closing.
When attempting to mock a method with a
static
return type (see https://php.watch/versions/8.0/static-return-type), then you'll get this error:Code: