Skip to content

[PhpUnitBridge] Add weak-verbose mode and match against message instead of test name #16789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/
class DeprecationErrorHandler
{
const MODE_WEAK = 'weak';
const MODE_WEAK_VERBOSE = 'weak-verbose';

private static $isRegistered = false;

public static function register($mode = false)
Expand Down Expand Up @@ -64,7 +67,7 @@ public static function register($mode = false)
$group = 'remaining';
}

if (isset($mode[0]) && '/' === $mode[0] && preg_match($mode, $class.'::'.$method)) {
if (isset($mode[0]) && '/' === $mode[0] && preg_match($mode, $msg)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this preg_match is there. Is it an undocumented feature of the helper ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah no, it is documented

$e = new \Exception($msg);
$r = new \ReflectionProperty($e, 'trace');
$r->setAccessible(true);
Expand All @@ -78,7 +81,7 @@ public static function register($mode = false)

exit(1);
}
if ('legacy' !== $group && 'weak' !== $mode) {
if ('legacy' !== $group && self::MODE_WEAK !== $mode) {
$ref = &$deprecations[$group][$msg]['count'];
++$ref;
$ref = &$deprecations[$group][$msg][$class.'::'.$method];
Expand Down Expand Up @@ -144,7 +147,7 @@ public static function register($mode = false)
if (!empty($notices)) {
echo "\n";
}
if ('weak' !== $mode && ($deprecations['unsilenced'] || $deprecations['remaining'] || $deprecations['other'])) {
if (self::MODE_WEAK !== $mode && self::MODE_WEAK_VERBOSE !== $mode && ($deprecations['unsilenced'] || $deprecations['remaining'] || $deprecations['other'])) {
exit(1);
}
});
Expand Down
17 changes: 9 additions & 8 deletions src/Symfony/Bridge/PhpUnit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ It comes with the following features:
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`. This will make the bridge ignore deprecation notices and
is useful to projects that must use deprecated interfaces for backward
compatibility reasons.
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.

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

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

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