Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8dea1ee

Browse filesBrowse files
committed
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
1 parent 2b8e441 commit 8dea1ee
Copy full SHA for 8dea1ee

File tree

5 files changed

+84
-6
lines changed
Filter options

5 files changed

+84
-6
lines changed

‎src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
+22-2Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ class DeprecationErrorHandler
6464
* The mode can alternatively be "/some-regexp/" to stop the test suite whenever
6565
* a deprecation message matches the given regular expression.
6666
*
67-
* @param int|string|false $mode The reporting mode, defaults to not allowing any deprecations
67+
* @param ?int|string|false $mode The reporting mode, defaults to not allowing any deprecations
6868
*/
6969
public static function register($mode = 0)
7070
{
71+
if (null === $mode) {
72+
$mode = self::getModeFromEnvironment();
73+
}
74+
7175
if (self::$isRegistered) {
7276
return;
7377
}
@@ -210,13 +214,29 @@ public function shutdown()
210214
});
211215
}
212216

217+
/**
218+
* @return string|false
219+
*/
220+
private static function getModeFromEnvironment()
221+
{
222+
if (isset($_SERVER['SYMFONY_DEPRECATIONS_HELPER'])) {
223+
return $_SERVER['SYMFONY_DEPRECATIONS_HELPER'];
224+
}
225+
226+
if (isset($_ENV['SYMFONY_DEPRECATIONS_HELPER'])) {
227+
return $_ENV['SYMFONY_DEPRECATIONS_HELPER'];
228+
}
229+
230+
return getenv('SYMFONY_DEPRECATIONS_HELPER');
231+
}
232+
213233
private function getConfiguration()
214234
{
215235
if (null !== $this->configuration) {
216236
return $this->configuration;
217237
}
218238
if (false === $mode = $this->mode) {
219-
$mode = getenv('SYMFONY_DEPRECATIONS_HELPER');
239+
$mode = self::getModeFromEnvironment();
220240
}
221241
if ('strict' === $mode) {
222242
return $this->configuration = Configuration::inStrictMode();

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/disabled.phpt
+2-2Lines 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');
+24Lines 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
+24Lines 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

‎src/Symfony/Bridge/PhpUnit/bootstrap.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/bootstrap.php
+12-2Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535
}
3636
}
3737

38-
if ('disabled' !== getenv('SYMFONY_DEPRECATIONS_HELPER')) {
39-
DeprecationErrorHandler::register(getenv('SYMFONY_DEPRECATIONS_HELPER'));
38+
if (isset($_SERVER['SYMFONY_DEPRECATIONS_HELPER']) && 'disabled' === $_SERVER['SYMFONY_DEPRECATIONS_HELPER']) {
39+
return;
40+
}
41+
42+
if (isset($_ENV['SYMFONY_DEPRECATIONS_HELPER']) && 'disabled' === $_ENV['SYMFONY_DEPRECATIONS_HELPER']) {
43+
return;
4044
}
45+
46+
if ('disabled' === getenv('SYMFONY_DEPRECATIONS_HELPER')) {
47+
return;
48+
}
49+
50+
DeprecationErrorHandler::register(null);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.