From 0ea8b1208e9f44358a670609cd2832f419c7b6d6 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 24 Oct 2017 20:45:13 +0100 Subject: [PATCH 1/5] Only use environment variable to determine if we should collect deprecations --- .../Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php | 1 + src/Symfony/Bridge/PhpUnit/bootstrap.php | 9 +++------ src/Symfony/Component/BrowserKit/Client.php | 5 +++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php index 6a0d9aec99284..fce5a7d3ade69 100644 --- a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php +++ b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php @@ -260,6 +260,7 @@ public function endTest($test, $time) } if ($this->runsInSeparateProcess) { + putenv('SYMFONY_DEPRECATIONS_SERIALIZE='); $deprecations = file_get_contents($this->runsInSeparateProcess); unlink($this->runsInSeparateProcess); foreach ($deprecations ? unserialize($deprecations) : array() as $deprecation) { diff --git a/src/Symfony/Bridge/PhpUnit/bootstrap.php b/src/Symfony/Bridge/PhpUnit/bootstrap.php index 2803caf02bcae..1247151a17a03 100644 --- a/src/Symfony/Bridge/PhpUnit/bootstrap.php +++ b/src/Symfony/Bridge/PhpUnit/bootstrap.php @@ -12,12 +12,9 @@ use Doctrine\Common\Annotations\AnnotationRegistry; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler; -// 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); - } - +// Detect if we need to serialize deprecations. +if ($ser = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) { + DeprecationErrorHandler::collectDeprecations($ser); return; } diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index 681bf697ef499..9f2033071a1d2 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -342,8 +342,9 @@ public function request($method, $uri, array $parameters = array(), array $files protected function doRequestInProcess($request) { $deprecationsFile = tempnam(sys_get_temp_dir(), 'deprec'); - putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$deprecationsFile); - $process = new PhpProcess($this->getScript($request), null, null); + $environment = getenv(); + $environment['SYMFONY_DEPRECATIONS_SERIALIZE'] = $deprecationsFile; + $process = new PhpProcess($this->getScript($request), null, $environment); $process->run(); if (file_exists($deprecationsFile)) { From 6523039193c35176388371ac361ffc8c5c627dcd Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 24 Oct 2017 20:55:53 +0100 Subject: [PATCH 2/5] Coding standards --- src/Symfony/Bridge/PhpUnit/bootstrap.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Bridge/PhpUnit/bootstrap.php b/src/Symfony/Bridge/PhpUnit/bootstrap.php index 1247151a17a03..2ad72081501df 100644 --- a/src/Symfony/Bridge/PhpUnit/bootstrap.php +++ b/src/Symfony/Bridge/PhpUnit/bootstrap.php @@ -15,6 +15,7 @@ // Detect if we need to serialize deprecations. if ($ser = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) { DeprecationErrorHandler::collectDeprecations($ser); + return; } From be56b3561a36626f47e1e7aefcd3fe2e7d9b0c08 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 25 Oct 2017 11:47:58 +0100 Subject: [PATCH 3/5] Remove only PHPUNIT_COMPOSER_INSTALL check --- src/Symfony/Bridge/PhpUnit/bootstrap.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/bootstrap.php b/src/Symfony/Bridge/PhpUnit/bootstrap.php index 2ad72081501df..570eb97389a9e 100644 --- a/src/Symfony/Bridge/PhpUnit/bootstrap.php +++ b/src/Symfony/Bridge/PhpUnit/bootstrap.php @@ -12,9 +12,11 @@ use Doctrine\Common\Annotations\AnnotationRegistry; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler; -// Detect if we need to serialize deprecations. -if ($ser = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) { - DeprecationErrorHandler::collectDeprecations($ser); +// Detect if we're loaded by an actual run of phpunit +if (!class_exists('PHPUnit_TextUI_Command', false) && !class_exists('PHPUnit\TextUI\Command', false)) { + if ($ser = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) { + DeprecationErrorHandler::collectDeprecations($ser); + } return; } From b0bcc20f35f7606a2f6d3d237225c54fd699faa6 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 25 Oct 2017 11:49:46 +0100 Subject: [PATCH 4/5] Revert other changes since they are no longer necessary --- .../Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php | 1 - src/Symfony/Component/BrowserKit/Client.php | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php index fce5a7d3ade69..6a0d9aec99284 100644 --- a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php +++ b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php @@ -260,7 +260,6 @@ public function endTest($test, $time) } if ($this->runsInSeparateProcess) { - putenv('SYMFONY_DEPRECATIONS_SERIALIZE='); $deprecations = file_get_contents($this->runsInSeparateProcess); unlink($this->runsInSeparateProcess); foreach ($deprecations ? unserialize($deprecations) : array() as $deprecation) { diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index 9f2033071a1d2..681bf697ef499 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -342,9 +342,8 @@ public function request($method, $uri, array $parameters = array(), array $files protected function doRequestInProcess($request) { $deprecationsFile = tempnam(sys_get_temp_dir(), 'deprec'); - $environment = getenv(); - $environment['SYMFONY_DEPRECATIONS_SERIALIZE'] = $deprecationsFile; - $process = new PhpProcess($this->getScript($request), null, $environment); + putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$deprecationsFile); + $process = new PhpProcess($this->getScript($request), null, null); $process->run(); if (file_exists($deprecationsFile)) { From 553edffbf37ce3b241b391974690630834af9c07 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 25 Oct 2017 12:20:23 +0100 Subject: [PATCH 5/5] Fix tests --- .../PhpUnit/Tests/DeprecationErrorHandler/default.phpt | 8 ++++++-- .../PhpUnit/Tests/DeprecationErrorHandler/disabled.phpt | 8 ++++++-- .../PhpUnit/Tests/DeprecationErrorHandler/regexp.phpt | 8 ++++++-- .../PhpUnit/Tests/DeprecationErrorHandler/weak.phpt | 8 ++++++-- .../weak_vendors_on_non_vendor.phpt | 8 ++++++-- .../DeprecationErrorHandler/weak_vendors_on_vendor.phpt | 8 ++++++-- 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/default.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/default.phpt index cd733724870cd..db60e3d25076e 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/default.phpt +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/default.phpt @@ -12,8 +12,12 @@ $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { $vendor = dirname($vendor); } -define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php'); -require PHPUNIT_COMPOSER_INSTALL; +// Fake class to ensure bootstrap.php calls DeprecationErrorHandler::register(). +class PHPUnit_TextUI_Command +{ + +} +require $vendor.'/vendor/autoload.php'; require_once __DIR__.'/../../bootstrap.php'; @trigger_error('root deprecation', E_USER_DEPRECATED); diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/disabled.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/disabled.phpt index 0115bbd24259a..b2aa84f3b84d7 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/disabled.phpt +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/disabled.phpt @@ -12,8 +12,12 @@ $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { $vendor = dirname($vendor); } -define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php'); -require PHPUNIT_COMPOSER_INSTALL; +// Fake class to ensure bootstrap.php calls DeprecationErrorHandler::register(). +class PHPUnit_TextUI_Command +{ + +} +require $vendor.'/vendor/autoload.php'; require_once __DIR__.'/../../bootstrap.php'; echo (int) set_error_handler('var_dump'); diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/regexp.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/regexp.phpt index 3b7207b85f8ee..2bea6d3bb5fcb 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/regexp.phpt +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/regexp.phpt @@ -12,8 +12,12 @@ $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { $vendor = dirname($vendor); } -define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php'); -require PHPUNIT_COMPOSER_INSTALL; +// Fake class to ensure bootstrap.php calls DeprecationErrorHandler::register(). +class PHPUnit_TextUI_Command +{ + +} +require $vendor.'/vendor/autoload.php'; require_once __DIR__.'/../../bootstrap.php'; @trigger_error('root deprecation', E_USER_DEPRECATED); diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak.phpt index 9e78d96e70efb..e65cd8648dfc0 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak.phpt +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak.phpt @@ -12,8 +12,12 @@ $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { $vendor = dirname($vendor); } -define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php'); -require PHPUNIT_COMPOSER_INSTALL; +// Fake class to ensure bootstrap.php calls DeprecationErrorHandler::register(). +class PHPUnit_TextUI_Command +{ + +} +require $vendor.'/vendor/autoload.php'; require_once __DIR__.'/../../bootstrap.php'; @trigger_error('root deprecation', E_USER_DEPRECATED); diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt index 7568d54a9ce91..a56db364171b2 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt @@ -12,8 +12,12 @@ $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { $vendor = dirname($vendor); } -define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php'); -require PHPUNIT_COMPOSER_INSTALL; +// Fake class to ensure bootstrap.php calls DeprecationErrorHandler::register(). +class PHPUnit_TextUI_Command +{ + +} +require $vendor.'/vendor/autoload.php'; require_once __DIR__.'/../../bootstrap.php'; @trigger_error('root deprecation', E_USER_DEPRECATED); diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_vendor.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_vendor.phpt index 7e9c6f8ed7682..f43ebde4929b7 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_vendor.phpt +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_vendor.phpt @@ -12,8 +12,12 @@ $vendor = __DIR__; while (!file_exists($vendor.'/vendor')) { $vendor = dirname($vendor); } -define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php'); -require PHPUNIT_COMPOSER_INSTALL; +// Fake class to ensure bootstrap.php calls DeprecationErrorHandler::register(). +class PHPUnit_TextUI_Command +{ + +} +require $vendor.'/vendor/autoload.php'; require_once __DIR__.'/../../bootstrap.php'; require __DIR__.'/fake_vendor/autoload.php'; require __DIR__.'/fake_vendor/acme/lib/deprecation_riddled.php';