Phake 框架:如何在 captureAll 上克隆对象?

Phake framework: how to clone objects on captureAll?

\Phake::captureAll returns 连续调用中使用的参数数组。 它适用于标量,或者当传递不同的对象时,但在使用同一对象时不是很有用。对于 data mapper 模拟,当 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
}

框架的 v2.x 无法实现。 The corresponding PR 正在考虑中,未来的版本可能会支持此类用例。