diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index dd396eeee407d..9d4f568b2eab2 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -54,9 +54,9 @@ public static function register($mode = 0) if (false === $mode) { $mode = getenv('SYMFONY_DEPRECATIONS_HELPER'); } - if (DeprecationErrorHandler::MODE_DISABLED !== $mode - && DeprecationErrorHandler::MODE_WEAK !== $mode - && DeprecationErrorHandler::MODE_WEAK_VENDORS !== $mode + if (self::MODE_DISABLED !== $mode + && self::MODE_WEAK !== $mode + && self::MODE_WEAK_VENDORS !== $mode && (!isset($mode[0]) || '/' !== $mode[0]) ) { $mode = preg_match('/^[1-9][0-9]*$/', $mode) ? (int) $mode : 0; @@ -106,7 +106,7 @@ public static function register($mode = 0) ); $deprecationHandler = function ($type, $msg, $file, $line, $context = array()) use (&$deprecations, $getMode, $UtilPrefix, $inVendors) { $mode = $getMode(); - if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || DeprecationErrorHandler::MODE_DISABLED === $mode) { + if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || self::MODE_DISABLED === $mode) { $ErrorHandler = $UtilPrefix.'ErrorHandler'; return $ErrorHandler::handleError($type, $msg, $file, $line, $context); @@ -114,7 +114,7 @@ public static function register($mode = 0) $trace = debug_backtrace(); $group = 'other'; - $isVendor = DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && $inVendors($file); + $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\\')))) { @@ -131,7 +131,7 @@ public static function register($mode = 0) // \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest() // then we need to use the serialized information to determine // if the error has been triggered from vendor code. - $isVendor = DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && isset($parsedMsg['triggering_file']) && $inVendors($parsedMsg['triggering_file']); + $isVendor = isset($parsedMsg['triggering_file']) && $inVendors($parsedMsg['triggering_file']); } else { $class = isset($trace[$i]['object']) ? \get_class($trace[$i]['object']) : $trace[$i]['class']; $method = $trace[$i]['function']; @@ -168,13 +168,13 @@ public static function register($mode = 0) exit(1); } - if ('legacy' !== $group && DeprecationErrorHandler::MODE_WEAK !== $mode) { + if ('legacy' !== $group && self::MODE_WEAK !== $mode) { $ref = &$deprecations[$group][$msg]['count']; ++$ref; $ref = &$deprecations[$group][$msg][$class.'::'.$method]; ++$ref; } - } elseif (DeprecationErrorHandler::MODE_WEAK !== $mode) { + } elseif (self::MODE_WEAK !== $mode) { $ref = &$deprecations[$group][$msg]['count']; ++$ref; } @@ -207,7 +207,7 @@ public static function register($mode = 0) $currErrorHandler = set_error_handler('var_dump'); restore_error_handler(); - if (DeprecationErrorHandler::MODE_WEAK === $mode) { + if (self::MODE_WEAK === $mode) { $colorize = function ($str) { return $str; }; } if ($currErrorHandler !== $deprecationHandler) { @@ -218,11 +218,7 @@ public static function register($mode = 0) return $b['count'] - $a['count']; }; - $groups = array('unsilenced', 'remaining'); - if (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode) { - $groups[] = 'remaining vendor'; - } - array_push($groups, 'legacy', 'other'); + $groups = array('unsilenced', 'remaining', 'remaining vendor', 'legacy', 'other'); $displayDeprecations = function ($deprecations) use ($colorize, $cmp, $groups) { foreach ($groups as $group) { @@ -253,16 +249,26 @@ public static function register($mode = 0) }; $displayDeprecations($deprecations); + $isPassing = function ($mode, $deprecations) { + if (self::MODE_WEAK === $mode) { + return true; + } + if (self::MODE_WEAK_VENDORS === $mode) { + return 0 === $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']; + } + + return 0 === $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['remaining vendorCount'] + $deprecations['otherCount']; + }; // store failing status - $isFailing = DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']; + $passesBeforeShutdown = $isPassing($mode, $deprecations); // reset deprecations array foreach ($deprecations as $group => $arrayOrInt) { $deprecations[$group] = \is_int($arrayOrInt) ? 0 : array(); } - register_shutdown_function(function () use (&$deprecations, $isFailing, $displayDeprecations, $mode) { + register_shutdown_function(function () use (&$deprecations, $passesBeforeShutdown, $displayDeprecations, $isPassing, $mode) { foreach ($deprecations as $group => $arrayOrInt) { if (0 < (\is_int($arrayOrInt) ? $arrayOrInt : \count($arrayOrInt))) { echo "Shutdown-time deprecations:\n"; @@ -270,7 +276,7 @@ public static function register($mode = 0) } } $displayDeprecations($deprecations); - if ($isFailing || DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) { + if (!$passesBeforeShutdown || !$isPassing($mode, $deprecations)) { exit(1); } });