Marcelo Marcelo - 3 months ago 14
PHP Question

How to mock the same method in Prophecy so it retruns different response in each of its calls

In pure PHPUnit mocking I can do something like this:

$mock->expects($this->at(0))
->method('isReady')
->will($this->returnValue(false));

$mock->expects($this->at(1))
->method('isReady')
->will($this->returnValue(true));


I was not able to do the same thing using Prophecy. Is it possible?

Answer

You can use:

$mock->isReady()->willReturn(false, true);

Apparently it's not documented (see https://gist.github.com/gquemener/292e7c5a4bbb72fd48a8) because Prophecy is opinionated and knows better than us. Sigh.

Comments