Ale*_*lex 12 php unit-testing phake
\ Phake :: captureAll返回连续调用中使用的参数数组.它可以与标量一起使用,或者在传递不同的对象时使用,但在使用相同的对象时不是很有用.对于数据映射器模拟,当CUT多次修改并持久化对象时,它经常发生.
在下面的例子中,我试图断言第一个$mock->fooWithArgument是用预期的参数调用的,但是找不到这样做的方法:
public function testArgumentCapturingAllValls()
{
$mock = \Phake::mock('PhakeTest_MockedClass');
$obj1 = new \stdClass;
$obj1->bar = 1;
$mock->fooWithArgument($obj1);
$obj1->bar = 2;
$mock->fooWithArgument($obj1);
\Phake::verify($mock, \Phake::atLeast(1))->fooWithArgument(\Phake::captureAll($toArgument));
$this->assertEquals(1, $toArgument[0]->bar); //fails, as both elements point to the same instance
}
Run Code Online (Sandbox Code Playgroud)