feature #16937 [PhpUnitBridge] Replace "weak-verbose" by "deprecations upper bound" mode (nicolas-grekas)

This PR was merged into the 2.8 branch.

Discussion
----------

[PhpUnitBridge] Replace "weak-verbose" by "deprecations upper bound" mode

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16789, #14475
| License       | MIT
| Doc PR        | -

This is a "new feature" that replaces a "new feature" not yet released but merged into 2.8.1. See #16789.
It is way more flexible to be able to specify the upper bound of remaining deprecation notices that you allow in your test suite. This allows lowering this number while deprecations are removed, step after step.

ping @WouterJ @Tobion @craue @fabpot @stof

Commits
-------

58cd3ee [PhpUnitBridge] Replace "weak-verbose" by "deprecations upper bound" mode
This commit is contained in:
Nicolas Grekas 2015-12-11 09:59:43 +01:00
commit b782cf97cb
2 changed files with 22 additions and 8 deletions

View File

@ -19,15 +19,29 @@ namespace Symfony\Bridge\PhpUnit;
class DeprecationErrorHandler
{
const MODE_WEAK = 'weak';
const MODE_WEAK_VERBOSE = 'weak-verbose';
private static $isRegistered = false;
public static function register($mode = false)
/**
* Registers and configures the deprecation handler.
*
* The following reporting modes are supported:
* - use "weak" to hide the deprecation report but keep a global count;
* - use "/some-regexp/" to stop the test suite whenever a deprecation
* message matches the given regular expression;
* - use a number to define the upper bound of allowed deprecations,
* making the test suite fail whenever more notices are trigerred.
*
* @param int|string|false $mode The reporting mode. Defaults to not allowing any deprecations.
*/
public static function register($mode = 0)
{
if (self::$isRegistered) {
return;
}
if (self::MODE_WEAK !== $mode && (!isset($mode[0]) || '/' !== $mode[0])) {
$mode = preg_match('/^[1-9][0-9]*$/', $mode) ? (int) $mode : 0;
}
$deprecations = array(
'unsilencedCount' => 0,
'remainingCount' => 0,
@ -147,7 +161,7 @@ class DeprecationErrorHandler
if (!empty($notices)) {
echo "\n";
}
if (DeprecationErrorHandler::MODE_WEAK !== $mode && DeprecationErrorHandler::MODE_WEAK_VERBOSE !== $mode && ($deprecations['unsilenced'] || $deprecations['remaining'] || $deprecations['other'])) {
if (DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) {
exit(1);
}
});

View File

@ -12,11 +12,11 @@ It comes with the following features:
* display the stack trace of a deprecation on-demand.
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` 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.
make tests fail. This can be changed by setting the `SYMFONY_DEPRECATIONS_HELPER`
environment variable to the maximum number of deprecations that are allowed to be
triggered before making the test suite fail. Alternatively, setting it to `weak`
will make the bridge ignore any 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: