8000 [Bridge\PhpUnit] Add "disabled" mode to SYMFONY_DEPRECATIONS_HELPER · symfony/symfony@89cd063 · GitHub
[go: up one dir, main page]

Skip to content

Commit 89cd063

Browse files
[Bridge\PhpUnit] Add "disabled" mode to SYMFONY_DEPRECATIONS_HELPER
1 parent 83ebf97 commit 89cd063

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,23 @@ public static function register($mode = 0)
3939
if (self::$isRegistered) {
4040
return;
4141
}
42-
if (self::MODE_WEAK !== $mode && (!isset($mode[0]) || '/' !== $mode[0])) {
43-
$mode = preg_match('/^[1-9][0-9]*$/', $mode) ? (int) $mode : 0;
44-
}
42+
43+
$mode = function () use ($mode) {
44+
static $memoizedMode = false;
45+
46+
if (false !== $memoizedMode) {
47+
return $memoizedMode;
48+
}
49+
if (false === $mode) {
50+
$mode = getenv('SYMFONY_DEPRECATIONS_HELPER');
51+
}
52+
if (DeprecationErrorHandler::MODE_WEAK !== $mode && (!isset($mode[0]) || '/' !== $mode[0])) {
53+
$mode = preg_match('/^[1-9][0-9]*$/', $mode) ? (int) $mode : 0;
54+
}
55+
56+
return $memoizedMode = $mode;
57+
};
58+
4559
$deprecations = array(
4660
'unsilencedCount' => 0,
4761
'remainingCount' => 0,
@@ -57,6 +71,7 @@ public static function register($mode = 0)
5771
return \PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context);
5872
}
5973

74+
$mode = $mode();
6075
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);
6176

6277
$i = count($trace);
@@ -95,13 +110,13 @@ public static function register($mode = 0)
95110

96111
exit(1);
97112
}
98-
if ('legacy' !== $group && self::MODE_WEAK !== $mode) {
113+
if ('legacy' !== $group && DeprecationErrorHandler::MODE_WEAK !== $mode) {
99114
$ref = &$deprecations[$group][$msg]['count'];
100115
++$ref;
101116
$ref = &$deprecations[$group][$msg][$class.'::'.$method];
102117
++$ref;
103118
}
104-
} else {
119+
} elseif (DeprecationErrorHandler::MODE_WEAK !== $mode) {
105120
$group = 'other';
106121
$ref = &$deprecations[$group][$msg]['count'];
107122
++$ref;
@@ -116,7 +131,7 @@ public static function register($mode = 0)
116131
restore_error_handler();
117132
self::register($mode);
118133
}
119-
} elseif (!isset($mode[0]) || '/' !== $mode[0]) {
134+
} else {
120135
self::$isRegistered = true;
121136
if (self::hasColorSupport()) {
122137
$colorize = function ($str, $red) {
@@ -128,9 +143,16 @@ public static function register($mode = 0)
128143
$colorize = function ($str) {return $str;};
129144
}
130145
register_shutdown_function(function () use ($mode, &$deprecations, $deprecationHandler, $colorize) {
146+
$mode = $mode();
147+
if (isset($mode[0]) && '/' === $mode[0]) {
148+
return;
149+
}
131150
$currErrorHandler = set_error_handler('var_dump');
132151
restore_error_handler();
133152

153+
if (DeprecationErrorHandler::MODE_WEAK === $mode) {
154+
$colorize = function ($str) {return $str;};
155+
}
134156
if ($currErrorHandler !== $deprecationHandler) {
135157
echo "\n", $colorize('THE ERROR HANDLER HAS CHANGED!', true), "\n";
136158
}

src/Symfony/Bridge/PhpUnit/bootstrap.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@
2424
AnnotationRegistry::registerLoader('class_exists');
2525
}
2626

27-
DeprecationErrorHandler::register(getenv('SYMFONY_DEPRECATIONS_HELPER'));
27+
if ('disabled' !== getenv('SYMFONY_DEPRECATIONS_HELPER')) {
28+
DeprecationErrorHandler::register(getenv('SYMFONY_DEPRECATIONS_HELPER'));
29+
}

0 commit comments

Comments
 (0)
0