File tree Expand file tree Collapse file tree 2 files changed +22
-8
lines changed
src/Symfony/Bridge/PhpUnit Expand file tree Collapse file tree 2 files changed +22
-8
lines changed Original file line number Diff line number Diff line change 19
19
class DeprecationErrorHandler
20
20
{
21
21
const MODE_WEAK = 'weak ' ;
22
- const MODE_WEAK_VERBOSE = 'weak-verbose ' ;
23
22
24
23
private static $ isRegistered = false ;
25
24
26
- public static function register ($ mode = false )
25
+ /**
26
+ * Registers and configures the deprecation handler.
27
+ *
28
+ * The following reporting modes are supported:
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
+ *
35
+ * @param int|string|false $mode The reporting mode. Defaults to not allowing any deprecations.
36
+ */
37
+ public static function register ($ mode = 0 )
27
38
{
28
39
if (self ::$ isRegistered ) {
29
40
return ;
30
41
}
42
+ if (self ::MODE_WEAK !== $ mode && (!isset ($ mode [0 ]) || '/ ' !== $ mode [0 ])) {
43
+ $ mode = preg_match ('/^[1-9][0-9]*$/ ' , $ mode ) ? (int ) $ mode : 0 ;
44
+ }
31
45
$ deprecations = array (
32
46
'unsilencedCount ' => 0 ,
33
47
'remainingCount ' => 0 ,
@@ -147,7 +161,7 @@ public static function register($mode = false)
147
161
if (!empty ($ notices )) {
148
162
echo "\n" ;
149
163
}
150
- if (DeprecationErrorHandler::MODE_WEAK !== $ mode && DeprecationErrorHandler:: MODE_WEAK_VERBOSE !== $ mode && ( $ deprecations ['unsilenced ' ] || $ deprecations ['remaining ' ] || $ deprecations ['other ' ]) ) {
164
+ if (DeprecationErrorHandler::MODE_WEAK !== $ mode && $ mode < $ deprecations ['unsilencedCount ' ] + $ deprecations ['remainingCount ' ] + $ deprecations ['otherCount ' ] ) {
151
165
exit (1 );
152
166
}
153
167
});
Original file line number Diff line number Diff line change @@ -12,11 +12,11 @@ It comes with the following features:
12
12
* display the stack trace of a deprecation on-demand.
13
13
14
14
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.
20
20
21
21
A summary of deprecation notices is displayed at the end of the test suite:
22
22
You can’t perform that action at this time.
0 commit comments