Skip to content

Commit e49b766

Browse files
committed
feature #16789 [PhpUnitBridge] Add weak-verbose mode and match against message instead of test name (nicolas-grekas)
This PR was merged into the 2.8 branch. Discussion ---------- [PhpUnitBridge] Add weak-verbose mode and match against message instead of test name | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14475 | License | MIT | Doc PR | - This is double a DX bug fix: - the weak-verbose allows showing messages but exit with 0 (see #14475) - matching against $class::$method was a mistake of mine: you can already `--filter` in phpunit to get by-test filtering but you can't select which message should be traced without this change. I stumbled upon this limitation while doing a Symfony 3 migration workshop... Commits ------- a670ff1 [PhpUnitBridge] Add weak-verbose mode and match against message instead of test name
2 parents 58e3b02 + a670ff1 commit e49b766

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
*/
1919
class DeprecationErrorHandler
2020
{
21+
const MODE_WEAK = 'weak';
22+
const MODE_WEAK_VERBOSE = 'weak-verbose';
23+
2124
private static $isRegistered = false;
2225

2326
public static function register($mode = false)
@@ -64,7 +67,7 @@ public static function register($mode = false)
6467
$group = 'remaining';
6568
}
6669

67-
if (isset($mode[0]) && '/' === $mode[0] && preg_match($mode, $class.'::'.$method)) {
70+
if (isset($mode[0]) && '/' === $mode[0] && preg_match($mode, $msg)) {
6871
$e = new \Exception($msg);
6972
$r = new \ReflectionProperty($e, 'trace');
7073
$r->setAccessible(true);
@@ -78,7 +81,7 @@ public static function register($mode = false)
7881

7982
exit(1);
8083
}
81-
if ('legacy' !== $group && 'weak' !== $mode) {
84+
if ('legacy' !== $group && self::MODE_WEAK !== $mode) {
8285
$ref = &$deprecations[$group][$msg]['count'];
8386
++$ref;
8487
$ref = &$deprecations[$group][$msg][$class.'::'.$method];
@@ -144,7 +147,7 @@ public static function register($mode = false)
144147
if (!empty($notices)) {
145148
echo "\n";
146149
}
147-
if ('weak' !== $mode && ($deprecations['unsilenced'] || $deprecations['remaining'] || $deprecations['other'])) {
150+
if (self::MODE_WEAK !== $mode && self::MODE_WEAK_VERBOSE !== $mode && ($deprecations['unsilenced'] || $deprecations['remaining'] || $deprecations['other'])) {
148151
exit(1);
149152
}
150153
});

src/Symfony/Bridge/PhpUnit/README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ It comes with the following features:
1414
By default any non-legacy-tagged or any non-@-silenced deprecation notices will
1515
make tests fail.
1616
This can be changed by setting the `SYMFONY_DEPRECATIONS_HELPER` environment
17-
variable to `weak`. This will make the bridge ignore deprecation notices and
18-
is useful to projects that must use deprecated interfaces for backward
19-
compatibility reasons.
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.
2020

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

@@ -53,8 +53,9 @@ You have to decide either to:
5353
forward compatibility;
5454
* or move them to the **Legacy** section (by using one of the above way).
5555

56-
In case you need to inspect the stack trace of a particular deprecation triggered by
57-
one of your unit tests, you can set the `SYMFONY_DEPRECATIONS_HELPER` env var to
58-
a regexp that matches this test case's `class::method` name. For example,
59-
`SYMFONY_DEPRECATIONS_HELPER=/^MyTest::testMethod$/ phpunit` will stop your test
60-
suite once a deprecation is triggered by the `MyTest::testMethod` test.
56+
In case you need to inspect the stack trace of a particular deprecation triggered
57+
by your unit tests, you can set the `SYMFONY_DEPRECATIONS_HELPER` env var to a
58+
regular expression that matches this deprecation's message, encapsed between `/`.
59+
For example, `SYMFONY_DEPRECATIONS_HELPER=/foobar/ phpunit` will stop your test
60+
suite once a deprecation notice is triggered whose message contains the "foobar"
61+
string.

0 commit comments

Comments
 (0)