2012-02-07 10:09:38 +00:00
|
|
|
<?php
|
|
|
|
|
2014-11-17 14:32:09 +00:00
|
|
|
if (PHP_VERSION_ID >= 50400 && gc_enabled()) {
|
2012-11-19 11:48:33 +00:00
|
|
|
// Disabling Zend Garbage Collection to prevent segfaults with PHP5.4+
|
|
|
|
// https://bugs.php.net/bug.php?id=53976
|
|
|
|
gc_disable();
|
|
|
|
}
|
|
|
|
|
2014-12-18 18:37:23 +00:00
|
|
|
/**
|
|
|
|
* Catch deprecation notices and print a summary report at the end of the test suite
|
|
|
|
*
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
class DeprecationErrorHandler
|
|
|
|
{
|
|
|
|
private static $isRegistered = false;
|
|
|
|
|
|
|
|
public static function register()
|
|
|
|
{
|
|
|
|
if (self::$isRegistered) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-05 19:35:39 +00:00
|
|
|
$deprecations = array(
|
|
|
|
'remainingCount' => 0,
|
|
|
|
'legacyCount' => 0,
|
|
|
|
'otherCount' => 0,
|
|
|
|
'remaining' => array(),
|
|
|
|
'legacy' => array(),
|
|
|
|
'other' => array(),
|
|
|
|
);
|
|
|
|
$deprecationHandler = function ($type, $msg, $file, $line, $context) use (&$deprecations) {
|
2014-12-18 18:37:23 +00:00
|
|
|
if (E_USER_DEPRECATED !== $type) {
|
|
|
|
return PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context);
|
|
|
|
}
|
|
|
|
|
2015-01-08 14:49:11 +00:00
|
|
|
$trace = debug_backtrace(PHP_VERSION_ID >= 50400 ? DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT : true);
|
2014-12-18 18:37:23 +00:00
|
|
|
|
|
|
|
$i = count($trace);
|
|
|
|
while (isset($trace[--$i]['class']) && ('ReflectionMethod' === $trace[$i]['class'] || 0 === strpos($trace[$i]['class'], 'PHPUnit_'))) {
|
|
|
|
// No-op
|
|
|
|
}
|
|
|
|
|
2015-01-08 14:49:11 +00:00
|
|
|
if (isset($trace[$i]['object']) || isset($trace[$i]['class'])) {
|
|
|
|
$class = isset($trace[$i]['object']) ? get_class($trace[$i]['object']) : $trace[$i]['class'];
|
2015-01-05 19:35:39 +00:00
|
|
|
$method = $trace[$i]['function'];
|
|
|
|
|
2015-01-09 06:49:26 +00:00
|
|
|
$type =
|
|
|
|
0 === strpos($method, 'testLegacy')
|
|
|
|
|| 0 === strpos($method, 'provideLegacy')
|
|
|
|
|| strpos($class, '\Legacy')
|
|
|
|
? 'legacy' : 'remaining';
|
2015-01-05 19:35:39 +00:00
|
|
|
|
|
|
|
if ('legacy' === $type && 0 === (error_reporting() & E_USER_DEPRECATED)) {
|
|
|
|
@++$deprecations[$type]['Silenced']['count'];
|
2014-12-18 18:37:23 +00:00
|
|
|
} else {
|
2015-01-05 19:35:39 +00:00
|
|
|
@++$deprecations[$type][$msg]['count'];
|
|
|
|
@++$deprecations[$type][$msg][$class.'::'.$method];
|
2014-12-18 18:37:23 +00:00
|
|
|
}
|
2015-01-05 19:35:39 +00:00
|
|
|
} else {
|
|
|
|
$type = 'other';
|
|
|
|
@++$deprecations[$type][$msg]['count'];
|
2014-12-18 18:37:23 +00:00
|
|
|
}
|
2015-01-05 19:35:39 +00:00
|
|
|
++$deprecations[$type.'Count'];
|
|
|
|
};
|
|
|
|
$oldErrorHandler = set_error_handler($deprecationHandler);
|
2014-12-18 18:37:23 +00:00
|
|
|
|
|
|
|
if (null !== $oldErrorHandler) {
|
|
|
|
restore_error_handler();
|
|
|
|
if (array('PHPUnit_Util_ErrorHandler', 'handleError') === $oldErrorHandler) {
|
|
|
|
restore_error_handler();
|
|
|
|
self::register();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
self::$isRegistered = true;
|
2015-01-05 19:35:39 +00:00
|
|
|
register_shutdown_function(function () use (&$deprecations, $deprecationHandler) {
|
|
|
|
|
|
|
|
$colorize = new \SebastianBergmann\Environment\Console();
|
|
|
|
|
|
|
|
if ($colorize->hasColorSupport()) {
|
|
|
|
$colorize = function ($str, $red) {
|
|
|
|
$color = $red ? '41;37' : '43;30';
|
|
|
|
|
|
|
|
return "\x1B[{$color}m{$str}\x1B[0m";
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
$colorize = function ($str) {return $str;};
|
|
|
|
}
|
|
|
|
|
|
|
|
$currErrorHandler = set_error_handler('var_dump');
|
|
|
|
restore_error_handler();
|
2014-12-18 18:37:23 +00:00
|
|
|
|
2015-01-05 19:35:39 +00:00
|
|
|
if ($currErrorHandler !== $deprecationHandler) {
|
|
|
|
echo "\n", $colorize('THE ERROR HANDLER HAS CHANGED!', true), "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$cmp = function ($a, $b) {
|
|
|
|
return $b['count'] - $a['count'];
|
|
|
|
};
|
|
|
|
|
|
|
|
foreach (array('remaining', 'legacy', 'other') as $type) {
|
|
|
|
if ($deprecations[$type]) {
|
|
|
|
echo "\n", $colorize(sprintf('%s deprecation notices (%d)', ucfirst($type), $deprecations[$type.'Count']), 'legacy' !== $type), "\n";
|
|
|
|
|
|
|
|
uasort($deprecations[$type], $cmp);
|
|
|
|
|
|
|
|
foreach ($deprecations[$type] as $msg => $notices) {
|
|
|
|
echo "\n", $msg, ': ', $notices['count'], "x\n";
|
|
|
|
|
|
|
|
arsort($notices);
|
|
|
|
|
|
|
|
foreach ($notices as $method => $count) {
|
|
|
|
if ('count' !== $method) {
|
|
|
|
echo ' ', $count, 'x in ', preg_replace('/(.*)\\\\(.*?::.*?)$/', '$2 from $1', $method), "\n";
|
2014-12-18 18:37:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-05 19:35:39 +00:00
|
|
|
}
|
|
|
|
if (!empty($notices)) {
|
|
|
|
echo "\n";
|
2014-12-18 18:37:23 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (class_exists('PHPUnit_Util_ErrorHandler')) {
|
|
|
|
DeprecationErrorHandler::register();
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:57:43 +01:00
|
|
|
$loader = require_once __DIR__.'/vendor/autoload.php';
|
2012-02-07 10:09:38 +00:00
|
|
|
|
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry;
|
|
|
|
|
|
|
|
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
|
2013-05-09 08:12:11 +01:00
|
|
|
|
|
|
|
return $loader;
|