Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e915bd

Browse files
bug #31954 [PhpunitBridge] Read environment variable from superglobals (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
2 parents f8b0bfd + 88cfcb5 commit 4e915bd

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@ private function getConfiguration()
219219
return $this->configuration;
220220
}
221221
if (false === $mode = $this->mode) {
222-
$mode = getenv('SYMFONY_DEPRECATIONS_HELPER');
222+
if (isset($_SERVER['SYMFONY_DEPRECATIONS_HELPER'])) {
223+
$mode = $_SERVER['SYMFONY_DEPRECATIONS_HELPER'];
224+
} elseif (isset($_ENV['SYMFONY_DEPRECATIONS_HELPER'])) {
225+
$mode = $_ENV['SYMFONY_DEPRECATIONS_HELPER'];
226+
} else {
227+
$mode = getenv('SYMFONY_DEPRECATIONS_HELPER');
228+
}
223229
}
224230
if ('strict' === $mode) {
225231
return $this->configuration = Configuration::inStrictMode();

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/disabled.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
Test DeprecationErrorHandler in weak mode
2+
Test DeprecationErrorHandler in disabled mode
33
--FILE--
44
<?php
55

6-
putenv('SYMFONY_DEPRECATIONS_HELPER=disabled');
6+
$_SERVER['SYMFONY_DEPRECATIONS_HELPER'] = 'disabled';
77
putenv('ANSICON');
88
putenv('ConEmuANSI');
99
putenv('TERM');
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Test DeprecationErrorHandler in disabled mode (via putenv)
3+
--FILE--
4+
<?php
5+
6+
$_ENV['SYMFONY_DEPRECATIONS_HELPER'] = 'disabled';
7+
putenv('ANSICON');
8+
putenv('ConEmuANSI');
9+
putenv('TERM');
10+
11+
$vendor = __DIR__;
12+
while (!file_exists($vendor.'/vendor')) {
13+
$vendor = dirname($vendor);
14+
}
15+
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
16+
require PHPUNIT_COMPOSER_INSTALL;
17+
require_once __DIR__.'/../../bootstrap.php';
18+
19+
echo (int) set_error_handler('var_dump');
20+
echo (int) class_exists('Symfony\Bridge\PhpUnit\DeprecationErrorHandler', false);
21+
22+
?>
23+
--EXPECTF--
24+
00
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Test DeprecationErrorHandler in disabled mode (via putenv)
3+
--FILE--
4+
<?php
5+
6+
putenv('SYMFONY_DEPRECATIONS_HELPER=disabled');
7+
putenv('ANSICON');
8+
putenv('ConEmuANSI');
9+
putenv('TERM');
10+
11+
$vendor = __DIR__;
12+
while (!file_exists($vendor.'/vendor')) {
13+
$vendor = dirname($vendor);
14+
}
15+
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
16+
require PHPUNIT_COMPOSER_INSTALL;
17+
require_once __DIR__.'/../../bootstrap.php';
18+
19+
echo (int) set_error_handler('var_dump');
20+
echo (int) class_exists('Symfony\Bridge\PhpUnit\DeprecationErrorHandler', false);
21+
22+
?>
23+
--EXPECTF--
24+
00

0 commit comments

Comments
 (0)