[Bridge\PhpUnit] Display the stack trace of a deprecation on-demand
This commit is contained in:
parent
9610602ab5
commit
5a88fb619f
@ -47,16 +47,37 @@ class DeprecationErrorHandler
|
|||||||
// No-op
|
// No-op
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 !== error_reporting()) {
|
if (isset($trace[$i]['object']) || isset($trace[$i]['class'])) {
|
||||||
$group = 'unsilenced';
|
|
||||||
$ref = &$deprecations[$group][$msg]['count'];
|
|
||||||
++$ref;
|
|
||||||
} elseif (isset($trace[$i]['object']) || isset($trace[$i]['class'])) {
|
|
||||||
$class = isset($trace[$i]['object']) ? get_class($trace[$i]['object']) : $trace[$i]['class'];
|
$class = isset($trace[$i]['object']) ? get_class($trace[$i]['object']) : $trace[$i]['class'];
|
||||||
$method = $trace[$i]['function'];
|
$method = $trace[$i]['function'];
|
||||||
|
|
||||||
$group = 0 === strpos($method, 'testLegacy') || 0 === strpos($method, 'provideLegacy') || 0 === strpos($method, 'getLegacy') || strpos($class, '\Legacy') || in_array('legacy', \PHPUnit_Util_Test::getGroups($class, $method), true) ? 'legacy' : 'remaining';
|
if (0 !== error_reporting()) {
|
||||||
|
$group = 'unsilenced';
|
||||||
|
} elseif (0 === strpos($method, 'testLegacy')
|
||||||
|
|| 0 === strpos($method, 'provideLegacy')
|
||||||
|
|| 0 === strpos($method, 'getLegacy')
|
||||||
|
|| strpos($class, '\Legacy')
|
||||||
|
|| in_array('legacy', \PHPUnit_Util_Test::getGroups($class, $method), true)
|
||||||
|
) {
|
||||||
|
$group = 'legacy';
|
||||||
|
} else {
|
||||||
|
$group = 'remaining';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($mode[0]) && '/' === $mode[0] && preg_match($mode, $class.'::'.$method)) {
|
||||||
|
$e = new \Exception($msg);
|
||||||
|
$r = new \ReflectionProperty($e, 'trace');
|
||||||
|
$r->setAccessible(true);
|
||||||
|
$r->setValue($e, array_slice($trace, 1, $i));
|
||||||
|
|
||||||
|
echo "\n".ucfirst($group).' deprecation triggered by '.$class.'::'.$method.':';
|
||||||
|
echo "\n".$msg;
|
||||||
|
echo "\nStack trace:";
|
||||||
|
echo "\n".str_replace(' '.getcwd().DIRECTORY_SEPARATOR, ' ', $e->getTraceAsString());
|
||||||
|
echo "\n";
|
||||||
|
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
if ('legacy' !== $group && 'weak' !== $mode) {
|
if ('legacy' !== $group && 'weak' !== $mode) {
|
||||||
$ref = &$deprecations[$group][$msg]['count'];
|
$ref = &$deprecations[$group][$msg]['count'];
|
||||||
++$ref;
|
++$ref;
|
||||||
@ -78,7 +99,7 @@ class DeprecationErrorHandler
|
|||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
self::register($mode);
|
self::register($mode);
|
||||||
}
|
}
|
||||||
} else {
|
} elseif (!isset($mode[0]) || '/' !== $mode[0]) {
|
||||||
self::$isRegistered = true;
|
self::$isRegistered = true;
|
||||||
if (self::hasColorSupport()) {
|
if (self::hasColorSupport()) {
|
||||||
$colorize = function ($str, $red) {
|
$colorize = function ($str, $red) {
|
||||||
|
@ -8,7 +8,8 @@ It comes with the following features:
|
|||||||
* disable the garbage collector;
|
* disable the garbage collector;
|
||||||
* enforce a consistent `C` locale;
|
* enforce a consistent `C` locale;
|
||||||
* auto-register `class_exists` to load Doctrine annotations;
|
* auto-register `class_exists` to load Doctrine annotations;
|
||||||
* print a user deprecation notices summary at the end of the test suite.
|
* print a user deprecation notices summary at the end of the test suite;
|
||||||
|
* display the stack trace of a deprecation on-demand.
|
||||||
|
|
||||||
By default any non-legacy-tagged or any non-@-silenced deprecation notices will
|
By default any non-legacy-tagged or any non-@-silenced deprecation notices will
|
||||||
make tests fail.
|
make tests fail.
|
||||||
@ -51,3 +52,9 @@ You have to decide either to:
|
|||||||
* update your code to not use deprecated interfaces anymore, thus gaining better
|
* update your code to not use deprecated interfaces anymore, thus gaining better
|
||||||
forward compatibility;
|
forward compatibility;
|
||||||
* or move them to the **Legacy** section (by using one of the above way).
|
* or move them to the **Legacy** section (by using one of the above way).
|
||||||
|
|
||||||
|
In you need to inspect the stack trace of a particular deprecation triggered by
|
||||||
|
one of your unit tests, you can set the `SYMFONY_DEPRECATIONS_HELPER` env var to
|
||||||
|
a regexp that matches this test case's `class::method` name. For example,
|
||||||
|
`SYMFONY_DEPRECATIONS_HELPER=/^MyTest::testMethod$/ phpunit` will stop your test
|
||||||
|
suite once a deprecation is triggered by the `MyTest::testMethod` test.
|
||||||
|
@ -41,6 +41,8 @@ use Symfony\Component\Form\Exception\InvalidArgumentException;
|
|||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*
|
||||||
|
* @deprecated since version 2.8, to be removed in 3.0. Use ArrayChoiceList instead.
|
||||||
*/
|
*/
|
||||||
class ArrayKeyChoiceList extends ArrayChoiceList
|
class ArrayKeyChoiceList extends ArrayChoiceList
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user