I am trying to add new route in test case extending Symfony\Bundle\FrameworkBundle\Test\KernelTestCase
that will throw exception, to test EventListener for it. Simplified tests will looks like this:
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');
}
It fails with:
Failed asserting that exception of type "Exception" is thrown.
How can I add route in-fly so calling it will work?
Aucun commentaire:
Enregistrer un commentaire