[HttpKernel] fixed a regression when no exception listeners are registered
This commit is contained in:
parent
bab6db59b5
commit
27930fb626
|
@ -229,7 +229,11 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
|
|||
if (!$event->hasResponse()) {
|
||||
$this->finishRequest($request, $type);
|
||||
|
||||
throw new \LogicException('No listeners of the "kernel.exception" event set a Response', 0, $e);
|
||||
if ($this->dispatcher->hasListeners(KernelEvents::EXCEPTION)) {
|
||||
throw new \LogicException('No listeners of the "kernel.exception" event set a Response', 0, $e);
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$response = $event->getResponse();
|
||||
|
|
|
@ -102,8 +102,8 @@ class ContainerAwareHttpKernelTest extends \PHPUnit_Framework_TestCase
|
|||
$this->fail('->handle() suppresses the controller exception');
|
||||
} catch (\PHPUnit_Framework_Exception $exception) {
|
||||
throw $exception;
|
||||
} catch (\LogicException $actual) {
|
||||
$this->assertSame($expected, $actual->getPrevious(), '->handle() throws the controller exception, wrapped when no listener');
|
||||
} catch (\Exception $actual) {
|
||||
$this->assertSame($expected, $actual, '->handle() throws the controller exception');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,17 +23,14 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
|
|||
|
||||
class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrue()
|
||||
{
|
||||
$exception = new \RuntimeException();
|
||||
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () use ($exception) { throw $exception; }));
|
||||
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () { throw new \RuntimeException(); }));
|
||||
|
||||
try {
|
||||
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
|
||||
$this->fail('LogicException expected');
|
||||
} catch (\LogicException $e) {
|
||||
$this->assertSame($exception, $e->getPrevious());
|
||||
}
|
||||
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in New Issue