8000 [HttpKernel] fixed a regression when no exception listeners are regis… · symfony/symfony@27930fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 27930fb

Browse files
committed
[HttpKernel] fixed a regression when no exception listeners are registered
1 parent bab6db5 commit 27930fb

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/Symfony/Component/HttpKernel/HttpKernel.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,11 @@ private function handleException(\Exception $e, $request, $type)
229229
if (!$event->hasResponse()) {
230230
$this->finishRequest($request, $type);
231231

232-
throw new \LogicException('No listeners of the "kernel.exception" event set a Response', 0, $e);
232+
if ($this->dispatcher->hasListeners(KernelEvents::EXCEPTION)) {
233+
throw new \LogicException('No listeners of the "kernel.exception" event set a Response', 0, $e);
234+
}
235+
236+
throw $e;
233237
}
234238

235239
$response = $event->getResponse();

src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ public function testHandleRestoresThePreviousRequestOnException($type)
102102
$this->fail('->handle() suppresses the controller exception');
103103
} catch (\PHPUnit_Framework_Exception $exception) {
104104
throw $exception;
105-
} catch (\LogicException $actual) {
106-
$this->assertSame($expected, $actual->getPrevious(), '->handle() throws the controller exception, wrapped when no listener');
105+
} catch (\Exception $actual) {
106+
$this->assertSame($expected, $actual, '->handle() throws the controller exception');
107107
}
108108
}
109109

src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,14 @@
2323

2424
class HttpKernelTest extends \PHPUnit_Framework_TestCase
2525
{
26+
/**
27+
* @expectedException \RuntimeException
28+
*/
2629
public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrue()
2730
{
28-
$exception = new \RuntimeException();
29-
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () use ($exception) { throw $exception; }));
31+
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () { throw new \RuntimeException(); }));
3032

31-
try {
32-
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
33-
$this->fail('LogicException expected');
34-
} catch (\LogicException $e) {
35-
$this->assertSame($exception, $e->getPrevious());
36-
}
33+
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
3734
}
3835

3936
/**

0 commit comments

Comments
 (0)
0