我想用不同的預期參數兩次調用我的模擬方法。這不起作用,因爲expects($this->once())
將在第二次調用時失敗。在PHPUnit中,如何在連續調用模擬方法時指示與()不同?
$mock->expects($this->once())
->method('foo')
->with('someValue');
$mock->expects($this->once())
->method('foo')
->with('anotherValue');
$mock->foo('someValue');
$mock->foo('anotherValue');
我也試過:
$mock->expects($this->exactly(2))
->method('foo')
->with('someValue');
但我怎麼添加有()第二個呼叫匹配嗎?
爲什麼你需要匹配參數?你不能使用onConsecutiveCalls()來說「第一次,返回這個,第二次返回」?你會正好使用(2)和onConsecutiveCalls() – fiunchinho 2011-04-29 22:34:20
相同的[問題](http://stackoverflow.com/questions/5484602/mock-in-phpunit-multiple-configuration-of-the-same-method-with - 不同的argume)從相關的塊。 – meze 2011-04-29 22:44:10
[phpunit mock method multiple calls with different arguments]可能重複(https://stackoverflow.com/questions/5988616/phpunit-mock-method-multiple-calls-with-different-arguments) – 2017-08-18 05:51:33