gpt4 book ai didi

php - Phake框架: how to clone objects on captureAll?

转载 作者:行者123 更新时间:2023-12-03 01:52:45 26 4
gpt4 key购买 nike

\Phake::captureAll 返回连续调用中使用的参数数组。它对于标量或者传递不同的对象时工作得很好,但当使用相同的对象时就不是很有用。 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正在考虑中, future 的版本可能支持此类用例。

关于php - Phake框架: how to clone objects on captureAll?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38566796/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com