0
我需要斷言3個不同的方法調用(具有相同的方法)與不同的參數和返回值。我可以使用$this->at()
來做到這一點。我怎樣才能斷言究竟是 3調用哪裏做的?
,通常要使用$this->exactly(3)
容易,但我不能在我的情況下使用它..PHPUnit assert方法調用索引和調用次數
我需要斷言3個不同的方法調用(具有相同的方法)與不同的參數和返回值。我可以使用$this->at()
來做到這一點。我怎樣才能斷言究竟是 3調用哪裏做的?
,通常要使用$this->exactly(3)
容易,但我不能在我的情況下使用它..PHPUnit assert方法調用索引和調用次數
你想用returnValueMap與模擬。然後您可以使用exactly(3)
,它將爲每個呼叫返回正確的值。
略從PHPUnit文檔變形例:
public function testReturnValueMapStub()
{
// Create a stub for the SomeClass class.
$stub = $this->getMockBuilder('SomeClass')
->getMock();
// Create a map of arguments to return values.
$map = array(
array('a', 'b', 'c', 'd'),
array('e', 'f', 'g', 'h'),
array('i', 'j', 'k', 'l'),
);
// Configure the stub.
$stub->expects($this->exactly(3))
->method('doSomething')
->will($this->returnValueMap($map));
// $stub->doSomething() returns different values depending on
// the provided arguments.
$this->assertEquals('d', $stub->doSomething('a', 'b', 'c'));
$this->assertEquals('h', $stub->doSomething('e', 'f', 'g'));
}
而且是有辦法也與地圖檢查輸入? – tamir
我無法找到。不幸的是,如果提供的值不在地圖中,則返回null。 – Schleis
很高興使用'returnValueMap()',但我的方法需要拋出其中一個調用。 – XedinUnknown