wiki.techinc.nl/tests/phpunit/MediaWikiPHPUnitResultPrinter.php
Timo Tijhof 0c910b1684 phpunit: Move "Logs generated by test" from middle to end of result
The previous output meant that when reviewing the build output,
it was quite hard to quickly find what the problem was and in
which test because the start of the result (which mentions the
test suite) and the expected/actual diff, were often separated
by dozens or hundreds of lines of "helpful" debug logs.

These are now moved to the after the expected/actual/stacktrace
portion so that "Name of test" and "expected/actual" remain
together.

Before

> 1) ResourceLoaderFilePathTest::testGetters
> === Logs generated by test case
> …
> …
> …
> …
> …
> …
> …
> ===
> Failed asserting that two strings are identical.
> --- Expected
> +++ Actual
> @@ @@
> -'dummy/pat'
> +'bla'
> /var/mediawiki/tests/phpunit/resourceloader/ResourceLoaderFilePathTest.php:22

After

> 1) ResourceLoaderFilePathTest::testGetters
> Failed asserting that two strings are identical.
> --- Expected
> +++ Actual
> @@ @@
> -'dummy/pat'
> +'bla'
> /var/mediawiki/tests/phpunit/resourceloader/ResourceLoaderFilePathTest.php:22
> === Logs generated by test case
> …
> …
> …
> …
> …
> …
> …
> ===

Change-Id: I31f1a4b730a0dd8597a059034b4e6abdc5f48552
2020-05-22 20:48:28 +01:00

17 lines
490 B
PHP

<?php
use PHPUnit\Framework\TestFailure;
use PHPUnit\TextUI\ResultPrinter;
class MediaWikiPHPUnitResultPrinter extends ResultPrinter {
protected function printDefectTrace( TestFailure $defect ) : void {
parent::printDefectTrace( $defect );
$test = $defect->failedTest();
if ( $test !== null && isset( $test->_formattedMediaWikiLogs ) ) {
$log = $test->_formattedMediaWikiLogs;
if ( $log ) {
$this->write( "=== Logs generated by test case\n{$log}\n===\n" );
}
}
}
}