wiki.techinc.nl/tests/phpunit/MediaWikiPHPUnitCommand.php
Erik Bernhardson 56ffbc2a4e Print logs generated during unit test when test fails
When a unit test fails it is possible, perhaps even likely in some
cases, that some code that was run logged useful information about
how that failure came to be.

Help people out, tell them what happened!

Change-Id: I30bbc31799a65024868678d052fec9aafacc1aff
2019-02-06 14:43:32 -08:00

44 lines
1.3 KiB
PHP

<?php
class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {
private $cliArgs;
private $logListener;
public function __construct( $ignorableOptions, $cliArgs ) {
$ignore = function ( $arg ) {
};
foreach ( $ignorableOptions as $option ) {
$this->longOptions[$option] = $ignore;
}
$this->cliArgs = $cliArgs;
}
protected function handleCustomTestSuite() {
// Use our suite.xml
if ( !isset( $this->arguments['configuration'] ) ) {
$this->arguments['configuration'] = __DIR__ . '/suite.xml';
}
// Add our own listeners
$this->arguments['listeners'][] = new MediaWikiPHPUnitTestListener;
$this->logListener = new MediaWikiLoggerPHPUnitTestListener;
$this->arguments['listeners'][] = $this->logListener;
// Output only to stderr to avoid "Headers already sent" problems
$this->arguments['stderr'] = true;
// We could create a printer instance and avoid passing the
// listener statically, but then we have to recreate the
// appropriate arguments handling + defaults.
if ( !isset( $this->arguments['printer'] ) ) {
$this->arguments['printer'] = MediaWikiPHPUnitResultPrinter::class;
}
}
protected function createRunner() {
MediaWikiPHPUnitResultPrinter::setLogListener( $this->logListener );
$runner = new MediaWikiTestRunner;
$runner->setMwCliArgs( $this->cliArgs );
return $runner;
}
}