diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index 4503c39102..fd2a1356a5 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -33,7 +33,7 @@ class DeprecationErrorHandler 'legacy' => array(), 'other' => array(), ); - $deprecationHandler = function ($type, $msg, $file, $line, $context) use (&$deprecations) { + $deprecationHandler = function ($type, $msg, $file, $line, $context) use (&$deprecations, $mode) { if (E_USER_DEPRECATED !== $type) { return \PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context); } @@ -51,10 +51,7 @@ class DeprecationErrorHandler $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 ('legacy' === $group && 0 === (error_reporting() & E_USER_DEPRECATED)) { - $ref =& $deprecations[$group]['Silenced']['count']; - ++$ref; - } else { + if ('legacy' !== $group && 'weak' !== $mode) { $ref =& $deprecations[$group][$msg]['count']; ++$ref; $ref =& $deprecations[$group][$msg][$class.'::'.$method]; @@ -99,7 +96,7 @@ class DeprecationErrorHandler }; foreach (array('remaining', 'legacy', 'other') as $group) { - if ($deprecations[$group]) { + if ($deprecations[$group.'Count']) { echo "\n", $colorize(sprintf('%s deprecation notices (%d)', ucfirst($group), $deprecations[$group.'Count']), 'legacy' !== $group), "\n"; uasort($deprecations[$group], $cmp); @@ -120,13 +117,8 @@ class DeprecationErrorHandler if (!empty($notices)) { echo "\n"; } - if ('weak' !== $mode) { - if ($deprecations['remaining'] || $deprecations['other']) { - exit(1); - } - if ('strict' === $mode && $deprecations['legacy'] && $deprecations['legacyCount'] !== $ref =& $deprecations['legacy']['Silenced']['count']) { - exit(1); - } + if ('weak' !== $mode && ($deprecations['remaining'] || $deprecations['other'])) { + exit(1); } }); } diff --git a/src/Symfony/Bridge/PhpUnit/README.md b/src/Symfony/Bridge/PhpUnit/README.md index 3cc8539831..7d84a3138d 100644 --- a/src/Symfony/Bridge/PhpUnit/README.md +++ b/src/Symfony/Bridge/PhpUnit/README.md @@ -9,19 +9,13 @@ It comes with the following features: * auto-register `class_exists` to load Doctrine annotations; * print a user deprecation notices summary at the end of the test suite. -Handling user deprecation notices is sensitive to the SYMFONY_DEPRECATIONS_HELPER -environment variable. This env var configures 3 behaviors depending on its value: +By default any non-legacy-tagged deprecation notice 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. - * when set to `strict`, all but silenced-legacy-tagged deprecation notices will - make tests fail. This is the recommended mode for best forward compatibility - * `weak` on the contrary will make tests ignore all deprecation notices. - This is the recommended mode for legacy projects that must use deprecated - interfaces for backward compatibility reasons. - * with any other value, all but silenced-or-not-legacy-tagged deprecation - notices will make tests fail. - -All three modes will display a summary of deprecation notices at the end of the -test suite, split in two groups: +A summary of deprecation notices is displayed at the end of the test suite: * **Legacy** deprecation notices denote tests that explicitly test some legacy interfaces. There are four ways to mark a test as legacy: @@ -36,8 +30,7 @@ Usage ----- Add this bridge to the `require-dev` section of your composer.json file -(not in `require`) with e.g. -`composer require --dev "symfony/phpunit-bridge"`. +(not in `require`) with e.g. `composer require --dev "symfony/phpunit-bridge"`. When running `phpunit`, you will see a summary of deprecation notices at the end of the test suite. @@ -48,15 +41,3 @@ You have to decide either to: * update your code to not use deprecated interfaces anymore, thus gaining better forward compatibility; * or move them to the **Legacy** section (by using one of the above way). - -After reviewing them, you should silence deprecations in the **Legacy** section -if you think they are triggered by tests dedicated to testing deprecated -interfaces. To do so, add the following line at the beginning of your legacy -test case or in the `setUp()` method of your legacy test class: -`$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);` - -Last but not least, you should then configure your C.I. to the reporting mode -that is appropriated to your project by setting SYMFONY_DEPRECATIONS_HELPER to -`strict`, `weak` or empty. It is recommended to start with `weak` mode, upgrade -your code as described above, then when the *Remaining/Other* sections are empty, -move to `strict` to keep forward compatibility on the long run. diff --git a/src/Symfony/Bridge/PhpUnit/bootstrap.php b/src/Symfony/Bridge/PhpUnit/bootstrap.php index d0bd8697ff..b25891538d 100644 --- a/src/Symfony/Bridge/PhpUnit/bootstrap.php +++ b/src/Symfony/Bridge/PhpUnit/bootstrap.php @@ -3,7 +3,8 @@ use Doctrine\Common\Annotations\AnnotationRegistry; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler; -if (!class_exists('PHPUnit_Util_ErrorHandler')) { +// Detect if we're loaded by an actual run of phpunit +if (!class_exists('PHPUnit_TextUI_Command', false)) { return; }