From f337a667a639764df1e42ab21d0f0d28b27fd1f4 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 24 Oct 2017 20:45:13 +0100 Subject: [PATCH 1/2] Ensure DeprecationErrorHandler::collectDeprecations() is triggered if SYMFONY_DEPRECATIONS_SERIALIZE is set --- .../PhpUnit/Legacy/SymfonyTestsListenerTrait.php | 1 + src/Symfony/Bridge/PhpUnit/bootstrap.php | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php index 6a0d9aec99284..2cb43e291fdd8 100644 --- a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php +++ b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php @@ -262,6 +262,7 @@ public function endTest($test, $time) if ($this->runsInSeparateProcess) { $deprecations = file_get_contents($this->runsInSeparateProcess); unlink($this->runsInSeparateProcess); + putenv('SYMFONY_DEPRECATIONS_SERIALIZE='); foreach ($deprecations ? unserialize($deprecations) : array() as $deprecation) { if ($deprecation[0]) { trigger_error(serialize(array('deprecation' => $deprecation[1], 'class' => $className, 'method' => $test->getName(false))), E_USER_DEPRECATED); diff --git a/src/Symfony/Bridge/PhpUnit/bootstrap.php b/src/Symfony/Bridge/PhpUnit/bootstrap.php index 2803caf02bcae..a265a129e6fdc 100644 --- a/src/Symfony/Bridge/PhpUnit/bootstrap.php +++ b/src/Symfony/Bridge/PhpUnit/bootstrap.php @@ -12,12 +12,15 @@ use Doctrine\Common\Annotations\AnnotationRegistry; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler; +// Detect if we need to serialize deprecations to a file. +if ($file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) { + DeprecationErrorHandler::collectDeprecations($file); + + return; +} + // Detect if we're loaded by an actual run of phpunit if (!defined('PHPUNIT_COMPOSER_INSTALL') && !class_exists('PHPUnit_TextUI_Command', false) && !class_exists('PHPUnit\TextUI\Command', false)) { - if ($ser = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) { - DeprecationErrorHandler::collectDeprecations($ser); - } - return; } From cd3c9319aacdf28c89ee611993551a9d5a1c330b Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Thu, 26 Oct 2017 22:18:33 +0100 Subject: [PATCH 2/2] Properly unset environment variable --- src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php index 2cb43e291fdd8..43394cea79706 100644 --- a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php +++ b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php @@ -262,7 +262,7 @@ public function endTest($test, $time) if ($this->runsInSeparateProcess) { $deprecations = file_get_contents($this->runsInSeparateProcess); unlink($this->runsInSeparateProcess); - putenv('SYMFONY_DEPRECATIONS_SERIALIZE='); + putenv('SYMFONY_DEPRECATIONS_SERIALIZE'); foreach ($deprecations ? unserialize($deprecations) : array() as $deprecation) { if ($deprecation[0]) { trigger_error(serialize(array('deprecation' => $deprecation[1], 'class' => $className, 'method' => $test->getName(false))), E_USER_DEPRECATED);