小编Kud*_*aty的帖子

PHP ZF2单元测试调度方法非常慢

我需要测试用ZF2编写的大型网站.有443个测试和大约10000个断言.使用代码覆盖测试需要6个小时!我想我发现了问题:在控制器的测试中,我使用了AbstractHttpControllerTestCase的调度方法.每次测试后(从秒到数十秒的分数),调度方法的执行时间都在增加.

我使用ZF 2.1.3,PHPUnit 3.7,PHP_CodeCoverage 1.2,Xdebug v2.2.1,PHP 5.4.7.

我的调度方法:

public function dispatch($url, $method = HttpRequest::METHOD_GET, $params = array())
{
    $s = microtime(true);

    parent::dispatch($url, $method, $params);

    $end = microtime(true) - $s;
    echo 'dis: '.$end."\n";

    return $this->getApplication()->getMvcEvent()->getResult();
}
Run Code Online (Sandbox Code Playgroud)

parent :: dispatch是AbstractHttpControllerTestCase的方法.

测试样本:

$result = $this->dispatch('/archive/finance/older');

$this->assertControllerName('skycontent\controller\article');
$this->assertActionName('archive');
$this->assertParamValue('older', true);
$this->assertParamValue('category', 'finance');

$vars = (array) $result->getVariables();

$this->assertArrayHasKey('archivePosts', $vars);
Run Code Online (Sandbox Code Playgroud)

请帮忙.谢谢.


更新:

我使用进程隔离和测试在大约15分钟内完成(没有代码覆盖)但我在测试中得到标记为跳过的错误:

PHPUnit_Framework_Exception: PHP Fatal error:  Uncaught exception 'Exception' with message 'Serialization of 'Closure' is not allowed' in -:44
Run Code Online (Sandbox Code Playgroud)

php phpunit unit-testing zend-test zend-framework2

6
推荐指数
1
解决办法
1075
查看次数

标签 统计

php ×1

phpunit ×1

unit-testing ×1

zend-framework2 ×1

zend-test ×1