Skip to content

Commit 5d99964

Browse files
Merge branch '2.8' into 3.3
* 2.8: [HttpKernel] DebugHandlersListener should always replace the existing exception handler
2 parents 753197f + 7fc3969 commit 5d99964

File tree

5 files changed

+89
-6
lines changed

5 files changed

+89
-6
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ install:
195195
elif [[ $deps = low ]]; then
196196
echo "$COMPONENTS" | parallel --gnu -j10% "tfold {} 'cd {} && $COMPOSER_UP --prefer-lowest --prefer-stable && $PHPUNIT_X'"
197197
elif [[ $PHP = hhvm* ]]; then
198-
$PHPUNIT --exclude-group benchmark,intl-data
198+
$PHPUNIT --exclude-group no-hhvm,benchmark,intl-data
199199
else
200200
echo "$COMPONENTS" | parallel --gnu "tfold {} $PHPUNIT_X {}"
201201
tfold tty-group $PHPUNIT --group tty

src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ public function testHandleDeprecation()
301301
@$handler->handleError(E_USER_DEPRECATED, 'Foo deprecation', __FILE__, __LINE__, array());
302302
}
303303

304+
/**
305+
* @group no-hhvm
306+
*/
304307
public function testHandleException()
305308
{
306309
try {
@@ -422,6 +425,9 @@ public function testBootstrappingLogger()
422425
$handler->setLoggers(array(E_DEPRECATED => array($mockLogger, LogLevel::WARNING)));
423426
}
424427

428+
/**
429+
* @group no-hhvm
430+
*/
425431
public function testSettingLoggerWhenExceptionIsBuffered()
426432
{
427433
$bootLogger = new BufferingLogger();
@@ -441,6 +447,9 @@ public function testSettingLoggerWhenExceptionIsBuffered()
441447
$handler->handleException($exception);
442448
}
443449

450+
/**
451+
* @group no-hhvm
452+
*/
444453
public function testHandleFatalError()
445454
{
446455
try {
@@ -499,6 +508,9 @@ public function testHandleErrorException()
499508
$this->assertStringStartsWith("Attempted to load class \"Foo\" from the global namespace.\nDid you forget a \"use\" statement", $args[0]->getMessage());
500509
}
501510

511+
/**
512+
* @group no-hhvm
513+
*/
502514
public function testHandleFatalErrorOnHHVM()
503515
{
504516
try {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
Test catching fatal errors when handlers are nested
3+
--FILE--
4+
<?php
5+
6+
namespace Symfony\Component\Debug;
7+
8+
$vendor = __DIR__;
9+
while (!file_exists($vendor.'/vendor')) {
10+
$vendor = dirname($vendor);
11+
}
12+
require $vendor.'/vendor/autoload.php';
13+
14+
set_error_handler('var_dump');
15+
set_exception_handler('var_dump');
16+
17+
ErrorHandler::register(null, false);
18+
19+
if (true) {
20+
class foo extends missing
21+
{
22+
}
23+
}
24+
25+
?>
26+
--EXPECTF--
27+
Fatal error: Class 'Symfony\Component\Debug\missing' not found in %s on line %d
28+
object(Symfony\Component\Debug\Exception\ClassNotFoundException)#%d (8) {
29+
["message":protected]=>
30+
string(131) "Attempted to load class "missing" from namespace "Symfony\Component\Debug".
31+
Did you forget a "use" statement for another namespace?"
32+
["string":"Exception":private]=>
33+
string(0) ""
34+
["code":protected]=>
35+
int(0)
36+
["file":protected]=>
37+
string(%d) "%s"
38+
["line":protected]=>
39+
int(%d)
40+
["trace":"Exception":private]=>
41+
array(0) {
42+
}
43+
["previous":"Exception":private]=>
44+
NULL
45+
["severity":protected]=>
46+
int(1)
47+
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,13 @@ public function configure(Event $event = null)
125125
}
126126
if ($this->exceptionHandler) {
127127
if ($handler instanceof ErrorHandler) {
128-
$h = $handler->setExceptionHandler('var_dump') ?: $this->exceptionHandler;
129-
$handler->setExceptionHandler($h);
130-
$handler = is_array($h) ? $h[0] : null;
128+
$h = $handler->setExceptionHandler('var_dump');
129+
if (is_array($h) && $h[0] instanceof ExceptionHandler) {
130+
$handler->setExceptionHandler($h);
131+
$handler = $h[0];
132+
} else {
133+
$handler->setExceptionHandler($this->exceptionHandler);
134+
}
131135
}
132136
if ($handler instanceof ExceptionHandler) {
133137
$handler->setHandler($this->exceptionHandler);

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
use Symfony\Component\HttpKernel\KernelEvents;
3030

3131
/**
32-
* DebugHandlersListenerTest.
33-
*
3432
* @author Nicolas Grekas <p@tchwork.com>
3533
*/
3634
class DebugHandlersListenerTest extends TestCase
@@ -132,4 +130,26 @@ public function testConsoleEvent()
132130

133131
$xHandler(new \Exception());
134132
}
133+
134+
public function testReplaceExistingExceptionHandler()
135+
{
136+
$userHandler = function () {};
137+
$listener = new DebugHandlersListener($userHandler);
138+
$eHandler = new ErrorHandler();
139+
$eHandler->setExceptionHandler('var_dump');
140+
141+
$exception = null;
142+
set_exception_handler(array($eHandler, 'handleException'));
143+
try {
144+
$listener->configure();
145+
} catch (\Exception $exception) {
146+
}
147+
restore_exception_handler();
148+
149+
if (null !== $exception) {
150+
throw $exception;
151+
}
152+
153+
$this->assertSame($userHandler, $eHandler->setExceptionHandler('var_dump'));
154+
}
135155
}

0 commit comments

Comments
 (0)