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

Skip to content

Commit 85c4243

Browse files
committed
Always segregate vendor and non vendor deprecations
Even if it does not make the exit code change, this is valuable information. Besides, not doing this reduces the complexity (fewer tests for the weak vendors mode). I introduced a new closure for computing whether the build is failing or not, named using positive logic so that things are easier to understand.
1 parent 631d718 commit 85c4243

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public static function register($mode = 0)
5454
if (false === $mode) {
5555
$mode = getenv('SYMFONY_DEPRECATIONS_HELPER');
5656
}
57-
if (DeprecationErrorHandler::MODE_DISABLED !== $mode
58-
&& DeprecationErrorHandler::MODE_WEAK !== $mode
59-
&& DeprecationErrorHandler::MODE_WEAK_VENDORS !== $mode
57+
if (self::MODE_DISABLED !== $mode
58+
&& self::MODE_WEAK !== $mode
59+
&& self::MODE_WEAK_VENDORS !== $mode
6060
&& (!isset($mode[0]) || '/' !== $mode[0])
6161
) {
6262
$mode = preg_match('/^[1-9][0-9]*$/', $mode) ? (int) $mode : 0;
@@ -106,15 +106,15 @@ public static function register($mode = 0)
106106
);
107107
$deprecationHandler = function ($type, $msg, $file, $line, $context = array()) use (&$deprecations, $getMode, $UtilPrefix, $inVendors) {
108108
$mode = $getMode();
109-
if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || DeprecationErrorHandler::MODE_DISABLED === $mode) {
109+
if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || self::MODE_DISABLED === $mode) {
110110
$ErrorHandler = $UtilPrefix.'ErrorHandler';
111111

112112
return $ErrorHandler::handleError($type, $msg, $file, $line, $context);
113113
}
114114

115115
$trace = debug_backtrace();
116116
$group = 'other';
117-
$isVendor = DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && $inVendors($file);
117+
$isVendor = $inVendors($file);
118118

119119
$i = \count($trace);
120120
while (1 < $i && (!isset($trace[--$i]['class']) || ('ReflectionMethod' === $trace[$i]['class'] || 0 === strpos($trace[$i]['class'], 'PHPUnit_') || 0 === strpos($trace[$i]['class'], 'PHPUnit\\')))) {
@@ -131,7 +131,7 @@ public static function register($mode = 0)
131131
// \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest()
132132
// then we need to use the serialized information to determine
133133
// if the error has been triggered from vendor code.
134-
$isVendor = DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && isset($parsedMsg['triggering_file']) && $inVendors($parsedMsg['triggering_file']);
134+
$isVendor = isset($parsedMsg['triggering_file']) && $inVendors($parsedMsg['triggering_file']);
135135
} else {
136136
$class = isset($trace[$i]['object']) ? \get_class($trace[$i]['object']) : $trace[$i]['class'];
137137
$method = $trace[$i]['function'];
@@ -168,13 +168,13 @@ public static function register($mode = 0)
168168

169169
exit(1);
170170
}
171-
if ('legacy' !== $group && DeprecationErrorHandler::MODE_WEAK !== $mode) {
171+
if ('legacy' !== $group && self::MODE_WEAK !== $mode) {
172172
$ref = &$deprecations[$group][$msg]['count'];
173173
++$ref;
174174
$ref = &$deprecations[$group][$msg][$class.'::'.$method];
175175
++$ref;
176176
}
177-
} elseif (DeprecationErrorHandler::MODE_WEAK !== $mode) {
177+
} elseif (self::MODE_WEAK !== $mode) {
178178
$ref = &$deprecations[$group][$msg]['count'];
179179
++$ref;
180180
}
@@ -207,7 +207,7 @@ public static function register($mode = 0)
207207
$currErrorHandler = set_error_handler('var_dump');
208208
restore_error_handler();
209209

210-
if (DeprecationErrorHandler::MODE_WEAK === $mode) {
210+
if (self::MODE_WEAK === $mode) {
211211
$colorize = function ($str) { return $str; };
212212
}
213213
if ($currErrorHandler !== $deprecationHandler) {
@@ -218,11 +218,7 @@ public static function register($mode = 0)
218218
return $b['count'] - $a['count'];
219219
};
220220

221-
$groups = array('unsilenced', 'remaining');
222-
if (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode) {
223-
$groups[] = 'remaining vendor';
224-
}
225-
array_push($groups, 'legacy', 'other');
221+
$groups = array('unsilenced', 'remaining', 'remaining vendor', 'legacy', 'other');
226222

227223
$displayDeprecations = function ($deprecations) use ($colorize, $cmp, $groups) {
228224
foreach ($groups as $group) {
@@ -253,24 +249,34 @@ public static function register($mode = 0)
253249
};
254250

255251
$displayDeprecations($deprecations);
252+
$isPassing = function ($mode, $deprecations) {
253+
if (self::MODE_WEAK === $mode) {
254+
return true;
255+
}
256+
if (self::MODE_WEAK_VENDORS === $mode) {
257+
return 0 === $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount'];
258+
}
259+
260+
return 0 === $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['remaining vendorCount'] + $deprecations['otherCount'];
261+
};
256262

257263
// store failing status
258-
$isFailing = DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount'];
264+
$passesBeforeShutdown = $isPassing($mode, $deprecations);
259265

260266
// reset deprecations array
261267
foreach ($deprecations as $group => $arrayOrInt) {
262268
$deprecations[$group] = \is_int($arrayOrInt) ? 0 : array();
263269
}
264270

265-
register_shutdown_function(function () use (&$deprecations, $isFailing, $displayDeprecations, $mode) {
271+
register_shutdown_function(function () use (&$deprecations, $passesBeforeShutdown, $displayDeprecations, $isPassing, $mode) {
266272
foreach ($deprecations as $group => $arrayOrInt) {
267273
if (0 < (\is_int($arrayOrInt) ? $arrayOrInt : \count($arrayOrInt))) {
268274
echo "Shutdown-time deprecations:\n";
269275
break;
270276
}
271277
}
272278
$displayDeprecations($deprecations);
273-
if ($isFailing || DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) {
279+
if (!$passesBeforeShutdown || !$isPassing($mode, $deprecations)) {
274280
exit(1);
275281
}
276282
});

0 commit comments

Comments
 (0)