php - In PHPUnit, how do I indicate different with() on successive calls to a mocked method? -
i want call mocked method twice different expected arguments. doesn't work because expects($this->once()) fail on second call.
$mock->expects($this->once()) ->method('foo') ->with('somevalue'); $mock->expects($this->once()) ->method('foo') ->with('anothervalue'); $mock->foo('somevalue'); $mock->foo('anothervalue'); i have tried:
$mock->expects($this->exactly(2)) ->method('foo') ->with('somevalue'); but how add with() match second call?
you need use at():
$mock->expects($this->at(0)) ->method('foo') ->with('somevalue'); $mock->expects($this->at(1)) ->method('foo') ->with('anothervalue'); $mock->foo('somevalue'); $mock->foo('anothervalue'); note indexes passed at() apply across method calls same mock object. if second method call bar() not change argument at().
Comments
Post a Comment