Skip to content

Commit

Permalink
bug #31954 [PhpunitBridge] Read environment variable from superglobal…
Browse files Browse the repository at this point in the history
…s (greg0ire)

This PR was merged into the 4.3 branch.

Discussion
----------

[PhpunitBridge] Read environment variable from superglobals

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31857
| License       | MIT
| Doc PR        | n/a

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

Commits
-------

88cfcb5 [PhpunitBridge] Read environment variable from superglobals
  • Loading branch information
nicolas-grekas committed Jun 26, 2019
2 parents f8b0bfd + 88cfcb5 commit 4e915bd
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Expand Up @@ -219,7 +219,13 @@ private function getConfiguration()
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();
Expand Down
@@ -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');
Expand Down
@@ -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
@@ -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

0 comments on commit 4e915bd

Please sign in to comment.