From a670ff1c9cfa4b5ab2ed17083a98e8720a278d7d Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 1 Dec 2015 20:49:56 +0100 Subject: [PATCH] [PhpUnitBridge] Add weak-verbose mode and match against message instead of test name --- .../Bridge/PhpUnit/DeprecationErrorHandler.php | 9 ++++++--- src/Symfony/Bridge/PhpUnit/README.md | 17 +++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index 81f59beeccde2..3bff0ed1b7a52 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -18,6 +18,9 @@ */ class DeprecationErrorHandler { + const MODE_WEAK = 'weak'; + const MODE_WEAK_VERBOSE = 'weak-verbose'; + private static $isRegistered = false; public static function register($mode = false) @@ -64,7 +67,7 @@ public static function register($mode = false) $group = 'remaining'; } - if (isset($mode[0]) && '/' === $mode[0] && preg_match($mode, $class.'::'.$method)) { + if (isset($mode[0]) && '/' === $mode[0] && preg_match($mode, $msg)) { $e = new \Exception($msg); $r = new \ReflectionProperty($e, 'trace'); $r->setAccessible(true); @@ -78,7 +81,7 @@ public static function register($mode = false) exit(1); } - if ('legacy' !== $group && 'weak' !== $mode) { + if ('legacy' !== $group && self::MODE_WEAK !== $mode) { $ref = &$deprecations[$group][$msg]['count']; ++$ref; $ref = &$deprecations[$group][$msg][$class.'::'.$method]; @@ -144,7 +147,7 @@ public static function register($mode = false) if (!empty($notices)) { echo "\n"; } - if ('weak' !== $mode && ($deprecations['unsilenced'] || $deprecations['remaining'] || $deprecations['other'])) { + if (self::MODE_WEAK !== $mode && self::MODE_WEAK_VERBOSE !== $mode && ($deprecations['unsilenced'] || $deprecations['remaining'] || $deprecations['other'])) { exit(1); } }); diff --git a/src/Symfony/Bridge/PhpUnit/README.md b/src/Symfony/Bridge/PhpUnit/README.md index 9d7ca89838c6e..ed5eda2ae5fca 100644 --- a/src/Symfony/Bridge/PhpUnit/README.md +++ b/src/Symfony/Bridge/PhpUnit/README.md @@ -14,9 +14,9 @@ It comes with the following features: By default any non-legacy-tagged or any non-@-silenced deprecation notices will make tests fail. This can be changed by setting the `SYMFONY_DEPRECATIONS_HELPER` environment -variable to `weak`. This will make the bridge ignore deprecation notices and -is useful to projects that must use deprecated interfaces for backward -compatibility reasons. +variable to `weak` or `weak-verbose`. This will make the bridge ignore +deprecation notices and is useful to projects that must use deprecated interfaces +for backward compatibility reasons. A summary of deprecation notices is displayed at the end of the test suite: @@ -53,8 +53,9 @@ You have to decide either to: forward compatibility; * or move them to the **Legacy** section (by using one of the above way). -In case 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. +In case you need to inspect the stack trace of a particular deprecation triggered +by your unit tests, you can set the `SYMFONY_DEPRECATIONS_HELPER` env var to a +regular expression that matches this deprecation's message, encapsed between `/`. +For example, `SYMFONY_DEPRECATIONS_HELPER=/foobar/ phpunit` will stop your test +suite once a deprecation notice is triggered whose message contains the "foobar" +string.