Phpunit 在调用 ExceptionController 的 showAction 方法时将测试标记为 "risky"
Phpunit marks test as "risky" when calling showAction method of ExceptionController
当尝试测试调用 ExceptionController
的 showAction
方法的 class 时(class 位于 vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php
),它标记为“risky" 测试,说:
Test code or tested code did not (only) close its own output buffers
示例代码:
$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....
为了解决问题,请求的header 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....
当尝试测试调用 ExceptionController
的 showAction
方法的 class 时(class 位于 vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php
),它标记为“risky" 测试,说:
Test code or tested code did not (only) close its own output buffers
示例代码:
$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....
为了解决问题,请求的header 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....