1
測試客戶端我試圖在測試情況下延長Symfony\Bundle\FrameworkBundle\Test\KernelTestCase
會拋出異常,測試的EventListener爲它增加新的航線。簡化測試將看起來像這樣:添加新路線的Symfony
public function testHandlingException()
{
$kernel = $this->createKernel(['environment' => 'test', 'debug' => true]);
$kernel->boot();
$client = $kernel->getContainer()->get('test.client');
$controller = new class extends Controller {
public function testAction()
{
throw new \Exception();
}
};
$route = new Route(
'route_500',
['_controller' => get_class($controller).'::testAction']
);
$client
->getContainer()
->get('router')
->getRouteCollection()
->add('route_500', $route);
$this->expectException(\Exception::class);
$client->request('GET', '/route_500');
}
它失敗:
Failed asserting that exception of type "Exception" is thrown.
我怎樣才能在飛所以調用它的工作添加路線?