Using TestDox is imho not ideal to use by default: * Far too noisy as a default, making it difficult to iterate by not having previous output nearby. * The custom "Logs generated" we add for debugging don't actually show up, not in the original failure that is buried between success mesages, and not in the summary. This is imho a requirement both for CI and local dev. * Test failures are immediately buried and flown past with a lot of other information. Proposal: * Restore default printer as this commit does, with the previous override for adding custom logs. * Once MWTestDox works correctly per the above, enable it by default for CI only, by adding `--printer MWTestDox` to phpunit:entrypoint in composer.json, which is basically only for use by CI. The vendor/bin/php, composer phpunit, and phpunit.php calls, and IDE integrations would would remain unaffected. One can easily pass `--printer MWTestDox` to bin/phpunit if preferred locally, or invoke `composer phpunit:entrypoint -- ...` instead at that point. Bug: T297287 Change-Id: I03391e2da1192156e220819d97ca7d8370199801
45 lines
1,013 B
PHP
45 lines
1,013 B
PHP
<?php
|
|
|
|
use PHPUnit\Framework\Test;
|
|
use PHPUnit\Framework\TestFailure;
|
|
use PHPUnit\Util\TestDox\CliTestDoxPrinter;
|
|
|
|
/**
|
|
* Custom version of PHPUnit TestDox.
|
|
*/
|
|
class MWTestDox 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 );
|
|
}
|
|
|
|
}
|