From 14925cb1d12465afb20097f5cdebd6b8aaba911e Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Thu, 4 Jan 2018 16:17:31 +0000 Subject: [PATCH 1/2] Use triggering file to determine weak vendors if when the test is run in a separate process --- src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php | 3 ++- .../Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index a108126a2eed8..b2ba758720563 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -121,6 +121,7 @@ public static function register($mode = 0) $msg = $parsedMsg['deprecation']; $class = $parsedMsg['class']; $method = $parsedMsg['method']; + $isWeak = DeprecationErrorHandler::MODE_WEAK === $mode || (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && $isVendor = $inVendors($parsedMsg['triggering_file'])); } else { $class = isset($trace[$i]['object']) ? get_class($trace[$i]['object']) : $trace[$i]['class']; $method = $trace[$i]['function']; @@ -261,7 +262,7 @@ public static function collectDeprecations($outputFile) return $ErrorHandler::handleError($type, $msg, $file, $line, $context); } - $deprecations[] = array(error_reporting(), $msg); + $deprecations[] = array(error_reporting(), $msg, $file); }); register_shutdown_function(function () use ($outputFile, &$deprecations) { diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php index d2ddddf3f23bb..a4f2262414696 100644 --- a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php +++ b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php @@ -272,10 +272,11 @@ public function endTest($test, $time) unlink($this->runsInSeparateProcess); putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); foreach ($deprecations ? unserialize($deprecations) : array() as $deprecation) { + $error = serialize(array('deprecation' => $deprecation[1], 'class' => $className, 'method' => $test->getName(false), 'triggering_file' => $deprecation[2])); if ($deprecation[0]) { - trigger_error(serialize(array('deprecation' => $deprecation[1], 'class' => $className, 'method' => $test->getName(false))), E_USER_DEPRECATED); + trigger_error($error, E_USER_DEPRECATED); } else { - @trigger_error(serialize(array('deprecation' => $deprecation[1], 'class' => $className, 'method' => $test->getName(false))), E_USER_DEPRECATED); + @trigger_error($error, E_USER_DEPRECATED); } } $this->runsInSeparateProcess = false; From bdcd52f3c90ce60a8d94fe2e48827a4ab5a97cba Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Thu, 4 Jan 2018 16:50:56 +0000 Subject: [PATCH 2/2] Add a comment --- src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index b2ba758720563..8330c6c44a99b 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -121,6 +121,11 @@ public static function register($mode = 0) $msg = $parsedMsg['deprecation']; $class = $parsedMsg['class']; $method = $parsedMsg['method']; + // If the deprecation has been triggered via + // \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. $isWeak = DeprecationErrorHandler::MODE_WEAK === $mode || (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && $isVendor = $inVendors($parsedMsg['triggering_file'])); } else { $class = isset($trace[$i]['object']) ? get_class($trace[$i]['object']) : $trace[$i]['class'];