2016-11-07 65 views
1

的的showAction方法時嘗試測試類調用ExceptionController(位於vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php類)的showAction方法它標誌着作爲「風險」測試,說:的PHPUnit標誌着測試爲「有風險」,呼籲ExceptionController

測試代碼或測試代碼不(僅)關閉其自己的輸出緩衝器

示例代碼:

$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.... 
爲了解決該問題,標題中的請求的 X-Php-Ob-Level應設置爲 1

回答

0

$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....