DeepCopy::recursiveCopy 当我使用 yii2 框架 运行 codeception 时出现异常

DeepCopy::recursiveCopy exception when i run codeception with yii2 framework

当 运行 codeception 时,我得到了很多错误:DeepCopy\DeepCopy::recursiveCopy。

这是个问题,让我很困惑!

  1. 当我只有 4 个单元测试用例时,我使用 codeception 玩得很好:
  2. 当我还在写单元测试用例的时候发生了..
  3. 我的测试中有 5 个单元测试 class 然后我得到了这个:

这是代码:

public function testGetComplexItemNeeds() {
    $this->specify('[getComplexItemNeeds] : ', function($expected) {
        $actual = \common\services\ConfigService::getComplexItemNeeds('300001');

        expect('getComplexItemNeeds', $actual)->equals($expected);
    }, ['examples' => [
            [0 => [
                    'gold' => 1,
                    'list' => [
                        300018 => 1,
                    ],
                ]
            ],
    ]]);
}

php_error.log:

PHP 195. DeepCopy\DeepCopy::copyArray($array = array ('0000000025e4802e0000000050ab4f11' => class tests\codeception\frontend\UnitTester { protected $scenario = class Codeception\Scenario { ... }; protected $friends = array (...) }, '0000000025e480490000000050ab4f11' => class Codeception\Scenario { protected $test = class tests\codeception\frontend\service\ConfigServiceTest { ... }; protected $steps = array (...);

x调试: 我使用 xdebug 跟踪问题发现,当函数 specifyCloneProperties 深度复制 unitTester 的 php 脚本时。

您可以在 bootstrap.php 文件中 turn off 深度克隆:

<?php
// disable deep cloning of properties inside specify block
\Codeception\Specify\Config::setDeepClone(false);
?>

或转on/offin the test。它还提高了测试的性能。