[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()) {
|
if (!$event->hasResponse()) {
|
||||||
$this->finishRequest($request, $type);
|
$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();
|
$response = $event->getResponse();
|
||||||
|
@ -102,8 +102,8 @@ class ContainerAwareHttpKernelTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->fail('->handle() suppresses the controller exception');
|
$this->fail('->handle() suppresses the controller exception');
|
||||||
} catch (\PHPUnit_Framework_Exception $exception) {
|
} catch (\PHPUnit_Framework_Exception $exception) {
|
||||||
throw $exception;
|
throw $exception;
|
||||||
} catch (\LogicException $actual) {
|
} catch (\Exception $actual) {
|
||||||
$this->assertSame($expected, $actual->getPrevious(), '->handle() throws the controller exception, wrapped when no listener');
|
$this->assertSame($expected, $actual, '->handle() throws the controller exception');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,17 +23,14 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
|
|||||||
|
|
||||||
class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @expectedException \RuntimeException
|
||||||
|
*/
|
||||||
public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrue()
|
public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrue()
|
||||||
{
|
{
|
||||||
$exception = new \RuntimeException();
|
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () { throw new \RuntimeException(); }));
|
||||||
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () use ($exception) { throw $exception; }));
|
|
||||||
|
|
||||||
try {
|
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
|
||||||
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
|
|
||||||
$this->fail('LogicException expected');
|
|
||||||
} catch (\LogicException $e) {
|
|
||||||
$this->assertSame($exception, $e->getPrevious());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user