From 7832b3260f62313c640a6ad99ea2a2bd8cf25d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 28 Feb 2017 10:27:10 +0100 Subject: [PATCH] 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. --- .../PhpUnit/DeprecationErrorHandler.php | 4 +- .../DeprecationErrorHandler/failure.phpt | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/failure.phpt diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index 6a7ad1fa98828..550cbe375f7a1 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -112,7 +112,7 @@ public static function register($mode = 0) $trace = debug_backtrace(true); $group = 'other'; - $isWeak = DeprecationErrorHandler::MODE_WEAK === $mode || (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && $isVendor = $inVendors($file)); + $isWeak = DeprecationErrorHandler::MODE_WEAK === $mode || (self::MODE_WEAK_VENDORS === $mode && $isVendor = $inVendors($file)); $i = count($trace); 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) $colorize = function ($str) { return $str; }; } if ($currErrorHandler !== $deprecationHandler) { - echo "\n", $colorize('THE ERROR HANDLER HAS CHANGED!', true), "\n"; + echo "\n", $colorize("THE ERROR HANDLER HAS CHANGED!\n".var_export(error_get_last(), true), true), "\n"; } $cmp = function ($a, $b) { diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/failure.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/failure.phpt new file mode 100644 index 0000000000000..2622b33e371e2 --- /dev/null +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/failure.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test DeprecationErrorHandler failure +--FILE-- + E_ERROR, + 'message' => 'failed to load flux capacitor', + 'file' => '/wherever/the/deprecation_handler_is', + 'line' => 42 + ); +} + +putenv('SYMFONY_DEPRECATIONS_HELPER'); +putenv('ANSICON'); +putenv('ConEmuANSI'); +putenv('TERM'); + +$vendor = __DIR__; +while (!file_exists($vendor.'/vendor')) { + $vendor = dirname($vendor); +} +define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php'); +require PHPUNIT_COMPOSER_INSTALL; +require_once __DIR__.'/../../bootstrap.php'; + +trigger_error('test failure', E_USER_DEPRECATED); +set_error_handler('var_dump'); + +--EXPECTF-- +THE ERROR HANDLER HAS CHANGED! +array ( + 'type' => 1, + 'message' => 'failed to load flux capacitor', + 'file' => '/wherever/the/deprecation_handler_is', + 'line' => 42, +) + +Other deprecation notices (1) + +test failure: 1x