Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7832b32

Browse filesBrowse files
Grégoire Parisgreg0ire
Grégoire Paris
authored andcommitted
Implement poor man's error handler
This line of code is hit when the error handler has failed. In that case, we want to get errors in the most reliable possible way, with very simple code. I think var_export and error_get_last are good candidates for that.
1 parent 41fd5d1 commit 7832b32
Copy full SHA for 7832b32

File tree

2 files changed

+45
-2
lines changed
Filter options

2 files changed

+45
-2
lines changed

‎src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static function register($mode = 0)
112112
$trace = debug_backtrace(true);
113113
$group = 'other';
114114

115-
$isWeak = DeprecationErrorHandler::MODE_WEAK === $mode || (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && $isVendor = $inVendors($file));
115+
$isWeak = DeprecationErrorHandler::MODE_WEAK === $mode || (self::MODE_WEAK_VENDORS === $mode && $isVendor = $inVendors($file));
116116

117117
$i = count($trace);
118118
while (1 < $i && (!isset($trace[--$i]['class']) || ('ReflectionMethod' === $trace[$i]['class'] || 0 === strpos($trace[$i]['class'], 'PHPUnit_') || 0 === strpos($trace[$i]['class'], 'PHPUnit\\')))) {
@@ -196,7 +196,7 @@ public static function register($mode = 0)
196196
$colorize = function ($str) { return $str; };
197197
}
198198
if ($currErrorHandler !== $deprecationHandler) {
199-
echo "\n", $colorize('THE ERROR HANDLER HAS CHANGED!', true), "\n";
199+
echo "\n", $colorize("THE ERROR HANDLER HAS CHANGED!\n".var_export(error_get_last(), true), true), "\n";
200200
}
201201

202202
$cmp = function ($a, $b) {
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Test DeprecationErrorHandler failure
3+
--FILE--
4+
<?php
5+
namespace Symfony\Bridge\PhpUnit;
6+
function error_get_last()
7+
{
8+
return array(
9+
'type' => E_ERROR,
10+
'message' => 'failed to load flux capacitor',
11+
'file' => '/wherever/the/deprecation_handler_is',
12+
'line' => 42
13+
);
14+
}
15+
16+
putenv('SYMFONY_DEPRECATIONS_HELPER');
17+
putenv('ANSICON');
18+
putenv('ConEmuANSI');
19+
putenv('TERM');
20+
21+
$vendor = __DIR__;
22+
while (!file_exists($vendor.'/vendor')) {
23+
$vendor = dirname($vendor);
24+
}
25+
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
26+
require PHPUNIT_COMPOSER_INSTALL;
27+
require_once __DIR__.'/../../bootstrap.php';
28+
29+
trigger_error('test failure', E_USER_DEPRECATED);
30+
set_error_handler('var_dump');
31+
32+
--EXPECTF--
33+
THE ERROR HANDLER HAS CHANGED!
34+
array (
35+
'type' => 1,
36+
'message' => 'failed to load flux capacitor',
37+
'file' => '/wherever/the/deprecation_handler_is',
38+
'line' => 42,
39+
)
40+
41+
Other deprecation notices (1)
42+
43+
test failure: 1x

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.