phpunit: Don't include PHPUnitCommand channel in MediaWikiLoggerPHPUnitTestListener
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 6 Apr 2019 22:53:30 +0000 (23:53 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Sat, 6 Apr 2019 23:10:16 +0000 (00:10 +0100)
Follows-up 96657099fc (T217489) adding MediaWikiLoggerPHPUnitTestListener.
It started printing messages from log channels to CLI output when there
is one or more failed assertions. This is useful.

But, it also interacts with MediaWikiPHPUnitTestListener from 2018,
which calls wfDebugLog('PHPUnitCommand', …) for every test and every
assertion. That allows one to later open debug.log and see MediaWiki's
messages interleaved with PHPUnit activity. This provides messages from
a much larger scope (including before test setup, and data providers).

But, this means we get:

 > There were N failures:
 > 1) ExampleTest::testGetThing
 > === Logs generated by test case
 > [PHPUnitCommand] [info] FAILURE in ExampleTest::testGetThing:
 > [PHPUnit\Framework\ExpectationFailedException] Failed asserting …
 > …
 > …
 > …
 > … {"private":false}
 > ===
 > Failed asserting that …
 > --- Expected
 > +++ Actual
 > @@ @@
 > …
 > /var/www/mediawiki/tests/phpunit/includes/…:…

This needlessly repeats the test name and method, and takes up
vertical space to describe the failed assertion in a way that is
less useful than the one that PHPUnit already prints after it.

Exclude these by default from CLI.

Bug: T217489
Change-Id: I0f471f82b16ba869d15389ed470bd73dc6deea78

tests/phpunit/MediaWikiLoggerPHPUnitTestListener.php

index f87afb0..8f34180 100644 (file)
@@ -83,6 +83,11 @@ class MediaWikiLoggerPHPUnitTestListener extends PHPUnit_Framework_BaseTestListe
        private function formatLogs( array $logs ) {
                $message = [];
                foreach ( $logs as $log ) {
+                       if ( $log['channel'] === 'PHPUnitCommand' ) {
+                               // Don't print the log of PHPUnit events while running PHPUnit,
+                               // because PHPUnit is already printing those already.
+                               continue;
+                       }
                        $message[] = sprintf(
                                '[%s] [%s] %s %s',
                                $log['channel'],