如何在Prophecy中模拟相同的方法,以便在每个调用中返回不同的响应 [英] How to mock the same method in Prophecy so it returns different response in each of its calls
本文介绍了如何在Prophecy中模拟相同的方法,以便在每个调用中返回不同的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在纯PHPUnit模拟中,我可以执行以下操作:
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?
推荐答案
您可以使用:
$mock->isReady()->willReturn(false, true);
显然没有记录(请参见 https://gist.github.com/gquemener/292e7c5a4bbb72fd48a8).
Apparently it's not documented (see https://gist.github.com/gquemener/292e7c5a4bbb72fd48a8).
这篇关于如何在Prophecy中模拟相同的方法,以便在每个调用中返回不同的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文