Skip to content

Commit a515383

Browse files
committed
bug symfony#17819 [HttpKernel] Prevent a fatal error when DebugHandlersListener is used with a kernel with no terminateWithException() method (jakzal)
This PR was merged into the 2.7 branch. Discussion ---------- [HttpKernel] Prevent a fatal error when DebugHandlersListener is used with a kernel with no terminateWithException() method | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - I just suffered from this bug on a project that used HttpKernelInterface implementation with no `terminateWithException() method (which is not part of the interface). Commits ------- 2849152 [HttpKernel] Prevent a fatal error when DebugHandlersListener is used with a kernel with no terminateWithException() method
2 parents 1c79c7b + 2849152 commit a515383

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ public function configure(Event $event = null)
9393
}
9494
if (!$this->exceptionHandler) {
9595
if ($event instanceof KernelEvent) {
96-
$this->exceptionHandler = array($event->getKernel(), 'terminateWithException');
96+
if (method_exists($event->getKernel(), 'terminateWithException')) {
97+
$this->exceptionHandler = array($event->getKernel(), 'terminateWithException');
98+
}
9799
} elseif ($event instanceof ConsoleEvent && $app = $event->getCommand()->getApplication()) {
98100
$output = $event->getOutput();
99101
if ($output instanceof ConsoleOutputInterface) {

src/Symfony/Component/HttpKernel/Tests/EventListener/DebugHandlersListenerTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
use Symfony\Component\Debug\ErrorHandler;
2222
use Symfony\Component\Debug\ExceptionHandler;
2323
use Symfony\Component\EventDispatcher\EventDispatcher;
24+
use Symfony\Component\HttpFoundation\Request;
25+
use Symfony\Component\HttpKernel\Event\KernelEvent;
2426
use Symfony\Component\HttpKernel\EventListener\DebugHandlersListener;
27+
use Symfony\Component\HttpKernel\HttpKernelInterface;
2528
use Symfony\Component\HttpKernel\KernelEvents;
2629

2730
/**
@@ -62,6 +65,31 @@ public function testConfigure()
6265
$this->assertSame(array($logger, LogLevel::INFO), $loggers[E_DEPRECATED]);
6366
}
6467

68+
public function testConfigureForHttpKernelWithNoTerminateWithException()
69+
{
70+
$listener = new DebugHandlersListener(null);
71+
$eHandler = new ErrorHandler();
72+
$event = new KernelEvent(
73+
$this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'),
74+
Request::create('/'),
75+
HttpKernelInterface::MASTER_REQUEST
76+
);
77+
78+
$exception = null;
79+
$h = set_exception_handler(array($eHandler, 'handleException'));
80+
try {
81+
$listener->configure($event);
82+
} catch (\Exception $exception) {
83+
}
84+
restore_exception_handler();
85+
86+
if (null !== $exception) {
87+
throw $exception;
88+
}
89+
90+
$this->assertNull($h);
91+
}
92+
6593
public function testConsoleEvent()
6694
{
6795
$dispatcher = new EventDispatcher();

0 commit comments

Comments
 (0)