Skip to content

Commit 33e7d8f

Browse files
[PhpUnitBridge] Replace "weak-verbose" by "deprecations upper bound" mode
1 parent e18a42a commit 33e7d8f

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,27 @@
1919
class DeprecationErrorHandler
2020
{
2121
const MODE_WEAK = 'weak';
22-
const MODE_WEAK_VERBOSE = 'weak-verbose';
2322

2423
private static $isRegistered = false;
2524

25+
/**
26+
* Registers and configures the deprecation handler.
27+
*
28+
* @param string|int $mode Configures the reporting mode:
29+
* - use "weak" to hide the deprecation report but keep a global count;
30+
* - use "/some-regexp/" to stop the test suite whenever a deprecation
31+
* message matches the given regular expression;
32+
* - use a number to define the upper bound of allowed deprecations,
33+
* making the test suite fail whenever more notices are trigerred.
34+
*/
2635
public static function register($mode = false)
2736
{
2837
if (self::$isRegistered) {
2938
return;
3039
}
40+
if (self::MODE_WEAK !== $mode && (!isset($mode[0]) || '/' !== $mode[0])) {
41+
$mode = preg_match('/^[1-9][0-9]*$/', $mode) ? (int) $mode : 0;
42+
}
3143
$deprecations = array(
3244
'unsilencedCount' => 0,
3345
'remainingCount' => 0,
@@ -147,7 +159,7 @@ public static function register($mode = false)
147159
if (!empty($notices)) {
148160
echo "\n";
149161
}
150-
if (DeprecationErrorHandler::MODE_WEAK !== $mode && DeprecationErrorHandler::MODE_WEAK_VERBOSE !== $mode && ($deprecations['unsilenced'] || $deprecations['remaining'] || $deprecations['other'])) {
162+
if (DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) {
151163
exit(1);
152164
}
153165
});

src/Symfony/Bridge/PhpUnit/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ It comes with the following features:
1212
* display the stack trace of a deprecation on-demand.
1313

1414
By default any non-legacy-tagged or any non-@-silenced deprecation notices will
15-
make tests fail.
16-
This can be changed by setting the `SYMFONY_DEPRECATIONS_HELPER` environment
17-
variable to `weak` or `weak-verbose`. This will make the bridge ignore
18-
deprecation notices and is useful to projects that must use deprecated interfaces
19-
for backward compatibility reasons.
15+
make tests fail. This can be changed by setting the `SYMFONY_DEPRECATIONS_HELPER`
16+
environment variable to the maximum number of deprecations that are allowed to be
17+
triggered before making the test suite fail. Alternatively, setting it to `weak`
18+
will make the bridge ignore any deprecation notices and is useful to projects
19+
that must use deprecated interfaces for backward compatibility reasons.
2020

2121
A summary of deprecation notices is displayed at the end of the test suite:
2222

0 commit comments

Comments
 (0)