8000 [2.7] print deprecation summary at end of tests · symfony/symfony@f268cbd · GitHub
[go: up one dir, main page]

Skip to content

Commit f268cbd

Browse files
[2.7] print deprecation summary at end of tests
1 parent f2c54c7 commit f268cbd

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

autoload.php.dist

Lines changed: 80 additions & 0 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,86 @@ if (PHP_VERSION_ID >= 50400 && gc_enabled()) {
66
gc_disable();
77
}
88

9+
/**
10+
* Catch deprecation notices and print a summary report at the end of the test suite
11+
*
12+
* @internal
13+
*/
14+
class DeprecationErrorHandler
15+
{
16+
private static $isRegistered = false;
17+
18+
public static function register()
19+
{
20+
if (self::$isRegistered) {
21+
return;
22+
}
23+
$deprecations = array(0);
24+
$oldErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context) use (&$deprecations) {
25+
if (E_USER_DEPRECATED !== $type) {
26+
return PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context);
27+
}
28+
29+
++$deprecations[0];
30+
$trace = debug_backtrace(PHP_VERSION_ID >= 50400 ? DEBUG_BACKTRACE_IGNORE_ARGS : false);
31+
32+
$i = count($trace);
33+
while (isset($trace[--$i]['class']) && ('ReflectionMethod' === $trace[$i]['class'] || 0 === strpos($trace[$i]['class'], 'PHPUnit_'))) {
34+
// No-op
35+
}
36+
37+
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];
40+
} else {
41+
$deprecations[$trace[$i]['class']][$trace[$i]['function']][$msg] = 1;
42+
}
43+
}
44+
});
45+
46+
if (null !== $oldErrorHandler) {
47+
restore_error_handler();
48+
if (array('PHPUnit_Util_ErrorHandler', 'handleError') === $oldErrorHandler) {
49+
restore_error_handler();
50+
self::register();
51+
}
52+
} else {
53+
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+
}
61+
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";
69+
}
70+
}
71+
}
72+
}
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+
}
79+
}
80+
});
81+
}
82+
}
83+
}
84+
85+
if (class_exists('PHPUnit_Util_ErrorHandler')) {
86+
DeprecationErrorHandler::register();
87+
}
88+
989
$loader = require_once __DIR__.'/vendor/autoload.php';
1090

1191
use Doctrine\Common\Annotations\AnnotationRegistry;

src/Symfony/Bundle/FrameworkBundle/Client.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,13 @@ protected function getScript($request)
160160
$profilerCode = '$kernel->getContainer()->get(\'profiler\')->enable();';
161161
}
162162

163+
$errorReporting = error_reporting();
164+
163165
$code = <<<EOF
164166
<?php
165167
168+
error_reporting($errorReporting);
169+
166170
if ('$autoloader') {
167171
require_once '$autoloader';
168172
}

0 commit comments

Comments
 (0)
0