Switch PHPUnit to use the more verbose TestDox format, which allows us to see exactly which tests have been executed. This is useful when making changes to test configuration. Use the MediaWikiPHPUnitResultPrinter to override the CliTestDoxPrinter and use the actual class names / test method names, instead of the prettified versions from TestDox, to improve greppability. Bug: T297287 Change-Id: I9d8561ff868e6ff0a44d32120f2799b34d25e618
45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\Test;
|
|
use PHPUnit\Framework\TestFailure;
|
|
use PHPUnit\Util\TestDox\CliTestDoxPrinter;
|
|
|
|
/**
|
|
* Custom result printer overriding the CliTestDoxPrinter and outputting logs for each test case.
|
|
*/
|
|
class MediaWikiPHPUnitResultPrinter extends CliTestDoxPrinter {
|
|
|
|
/**
|
|
* @param TestFailure $defect
|
|
* @return void
|
|
*/
|
|
protected function printDefectTrace( TestFailure $defect ): void {
|
|
parent::printDefectTrace( $defect );
|
|
$test = $defect->getTestName();
|
|
$log = MediaWikiLoggerPHPUnitExtension::$testsCollection[$test] ?? null;
|
|
if ( $log ) {
|
|
$this->write( "=== Logs generated by test case\n{$log}\n===\n" );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Print the plain test name, not the prettified version from TestDox.
|
|
*
|
|
* @param Test $test
|
|
* @return string
|
|
*/
|
|
protected function formatTestName( Test $test ): string {
|
|
return $test->getName();
|
|
}
|
|
|
|
/**
|
|
* Print the plain class name, not the prettified version from TestDox.
|
|
*
|
|
* @param Test $test
|
|
* @return string
|
|
*/
|
|
protected function formatClassName( Test $test ): string {
|
|
return get_class( $test );
|
|
}
|
|
|
|
}
|