Phpunit将测试标记为"风险"在调用ExceptionController的showAction方法时

时间:2016-11-07 17:26:32

标签: php unit-testing symfony phpunit twig

当我尝试测试一个调用showAction ExceptionController vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php方法的类时,它会标记为" 冒险& #34;测试,说:

  

测试代码或测试代码没有(仅)关闭自己的输出缓冲区

示例代码:

    $request = Request::create('whatever', 'GET');
    $request->attributes->set('showException', false);

    $exception = FlattenException::create(new \Exception(), 404);

    $controller = new ExceptionController($twig, true);

    $response = $controller->showAction($request, $exception, null);

    // some assertions....

1 个答案:

答案 0 :(得分:0)

为了解决问题,请求的标头X-Php-Ob-Level应设置为1

$request->headers->set('X-Php-Ob-Level', 1);

示例代码:

$request = Request::create('whatever', 'GET');
$request->headers->set('X-Php-Ob-Level', 1);
$request->attributes->set('showException', false);

$exception = FlattenException::create(new \Exception(), 404);

$controller = new ExceptionController($twig, true);

$response = $controller->showAction($request, $exception, null);

// some assertions....