Skip to content

Commit dece1e0

Browse files
committed
minor #13279 Enhance deprecation summary at end of tests (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- Enhance deprecation summary at end of tests | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Splits deprecations triggered by legacy tests and non-legacy ones. Commits ------- 7b8cf01 Enhance deprecation summary at end of tests
2 parents 07ec37c + 7b8cf01 commit dece1e0

File tree

1 file changed

+65
-27
lines changed

1 file changed

+65
-27
lines changed

autoload.php.dist

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@ class DeprecationErrorHandler
2020
if (self::$isRegistered) {
2121
return;
2222
}
23-
$deprecations = array(0);
24-
$oldErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context) use (&$deprecations) {
23+
$deprecations = array(
24+
'remainingCount' => 0,
25+
'legacyCount' => 0,
26+
'otherCount' => 0,
27+
'remaining' => array(),
28+
'legacy' => array(),
29+
'other' => array(),
30+
);
31+
$deprecationHandler = function ($type, $msg, $file, $line, $context) use (&$deprecations) {
2532
if (E_USER_DEPRECATED !== $type) {
2633
return PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context);
2734
}
2835

29-
++$deprecations[0];
3036
$trace = debug_backtrace(PHP_VERSION_ID >= 50400 ? DEBUG_BACKTRACE_IGNORE_ARGS : false);
3137

3238
$i = count($trace);
@@ -35,13 +41,24 @@ class DeprecationErrorHandler
3541
}
3642

3743
if (isset($trace[$i]['class'])) {
38-
if (isset($deprecations[$trace[$i]['class']][$trace[$i]['function']][$msg])) {
39-
++$deprecations[$trace[$i]['class']][$trace[$i]['function']][$msg];
44+
$class = $trace[$i]['class'];
45+
$method = $trace[$i]['function'];
46+
47+
$type = 0 === strpos($method, 'testLegacy') || 0 === strpos($method, 'provideLegacy') || strpos($class, '\Legacy') ? 'legacy' : 'remaining';
48+
49+
if ('legacy' === $type && 0 === (error_reporting() & E_USER_DEPRECATED)) {
50+
@++$deprecations[$type]['Silenced']['count'];
4051
} else {
41-
$deprecations[$trace[$i]['class']][$trace[$i]['function']][$msg] = 1;
52+
@++$deprecations[$type][$msg]['count'];
53+
@++$deprecations[$type][$msg][$class.'::'.$method];
4254
}
55+
} else {
56+
$type = 'other';
57+
@++$deprecations[$type][$msg]['count'];
4358
}
44-
});
59+
++$deprecations[$type.'Count'];
60+
};
61+
$oldErrorHandler = set_error_handler($deprecationHandler);
4562

4663
if (null !== $oldErrorHandler) {
4764
restore_error_handler();
@@ -51,31 +68,52 @@ class DeprecationErrorHandler
5168
}
5269
} else {
5370
self::$isRegistered = true;
54-
register_shutdown_function(function () use (&$deprecations) {
55-
if ($deprecations[0]) {
56-
if (function_exists('posix_isatty') && @posix_isatty(STDOUT)) {
57-
echo "\n\x1B[43;30mDeprecation notices ($deprecations[0]):\x1B[0m\n";
58-
} else {
59-
echo "\nDeprecation notices ($deprecations[0]):\n";
60-
}
71+
register_shutdown_function(function () use (&$deprecations, $deprecationHandler) {
72+
73+
$colorize = new \SebastianBergmann\Environment\Console();
74+
75+
if ($colorize->hasColorSupport()) {
76+
$colorize = function ($str, $red) {
77+
$color = $red ? '41;37' : '43;30';
78+
79+
return "\x1B[{$color}m{$str}\x1B[0m";
80+
};
81+
} else {
82+
$colorize = function ($str) {return $str;};
83+
}
84+
85+
$currErrorHandler = set_error_handler('var_dump');
86+
restore_error_handler();
6187

62-
foreach ($deprecations as $class => $notices) {
63-
if (0 !== $class) {
64-
echo "\n{$class}\n";
65-
foreach ($notices as $method => $notices) {
66-
echo " ->{$method}()\n";
67-
foreach ($notices as $msg => $freq) {
68-
echo " {$msg}: $freq\n";
88+
if ($currErrorHandler !== $deprecationHandler) {
89+
echo "\n", $colorize('THE ERROR HANDLER HAS CHANGED!', true), "\n";
90+
}
91+
92+
$cmp = function ($a, $b) {
93+
return $b['count'] - $a['count'];
94+
};
95+
96+
foreach (array('remaining', 'legacy', 'other') as $type) {
97+
if ($deprecations[$type]) {
98+
echo "\n", $colorize(sprintf('%s deprecation notices (%d)', ucfirst($type), $deprecations[$type.'Count']), 'legacy' !== $type), "\n";
99+
100+
uasort($deprecations[$type], $cmp);
101+
102+
foreach ($deprecations[$type] as $msg => $notices) {
103+
echo "\n", $msg, ': ', $notices['count'], "x\n";
104+
105+
arsort($notices);
106+
107+
foreach ($notices as $method => $count) {
108+
if ('count' !== $method) {
109+
echo ' ', $count, 'x in ', preg_replace('/(.*)\\\\(.*?::.*?)$/', '$2 from $1', $method), "\n";
69110
}
70111
}
71112
}
72113
}
73-
} else {
74-
if (function_exists('posix_isatty') && @posix_isatty(STDOUT)) {
75-
echo "\n\x1B[42;30mNo deprecation notice\x1B[0m\n";
76-
} else {
77-
echo "\nNo deprecation notice\n";
78-
}
114+
}
115+
if (!empty($notices)) {
116+
echo "\n";
79117
}
80118
});
81119
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy