[PhpunitBridge] Read environment variable from superglobals

The Dotenv component has recently been switched to using superglobals
instead of putenv(). Let us support both and give priority to
superglobals.

Closes #31857
This commit is contained in:
Grégoire Paris 2019-06-08 12:20:20 +02:00 committed by Nicolas Grekas
parent 2b8e44164e
commit 88cfcb536d
4 changed files with 57 additions and 3 deletions

View File

@ -216,7 +216,13 @@ class DeprecationErrorHandler
return $this->configuration;
}
if (false === $mode = $this->mode) {
$mode = getenv('SYMFONY_DEPRECATIONS_HELPER');
if (isset($_SERVER['SYMFONY_DEPRECATIONS_HELPER'])) {
$mode = $_SERVER['SYMFONY_DEPRECATIONS_HELPER'];
} elseif (isset($_ENV['SYMFONY_DEPRECATIONS_HELPER'])) {
$mode = $_ENV['SYMFONY_DEPRECATIONS_HELPER'];
} else {
$mode = getenv('SYMFONY_DEPRECATIONS_HELPER');
}
}
if ('strict' === $mode) {
return $this->configuration = Configuration::inStrictMode();

View File

@ -1,9 +1,9 @@
--TEST--
Test DeprecationErrorHandler in weak mode
Test DeprecationErrorHandler in disabled mode
--FILE--
<?php
putenv('SYMFONY_DEPRECATIONS_HELPER=disabled');
$_SERVER['SYMFONY_DEPRECATIONS_HELPER'] = 'disabled';
putenv('ANSICON');
putenv('ConEmuANSI');
putenv('TERM');

View File

@ -0,0 +1,24 @@
--TEST--
Test DeprecationErrorHandler in disabled mode (via putenv)
--FILE--
<?php
$_ENV['SYMFONY_DEPRECATIONS_HELPER'] = 'disabled';
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';
echo (int) set_error_handler('var_dump');
echo (int) class_exists('Symfony\Bridge\PhpUnit\DeprecationErrorHandler', false);
?>
--EXPECTF--
00

View File

@ -0,0 +1,24 @@
--TEST--
Test DeprecationErrorHandler in disabled mode (via putenv)
--FILE--
<?php
putenv('SYMFONY_DEPRECATIONS_HELPER=disabled');
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';
echo (int) set_error_handler('var_dump');
echo (int) class_exists('Symfony\Bridge\PhpUnit\DeprecationErrorHandler', false);
?>
--EXPECTF--
00