test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / MediaWikiPHPUnitCommand.php
blobf5760ea0d4771675dce44b9e9fa34c60df06a0f0
1 <?php
3 class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {
5 public static $additionalOptions = array(
6 'regex=' => false,
7 'file=' => false,
8 'use-filebackend=' => false,
9 'use-bagostuff=' => false,
10 'use-jobqueue=' => false,
11 'keep-uploads' => false,
12 'use-normal-tables' => false,
13 'reuse-db' => false,
14 'wiki=' => false,
17 public function __construct() {
18 foreach ( self::$additionalOptions as $option => $default ) {
19 $this->longOptions[$option] = $option . 'Handler';
23 public static function main( $exit = true ) {
24 $command = new self;
26 if ( wfIsWindows() ) {
27 # Windows does not come anymore with ANSI.SYS loaded by default
28 # PHPUnit uses the suite.xml parameters to enable/disable colors
29 # which can be then forced to be enabled with --colors.
30 # The below code inject a parameter just like if the user called
31 # phpunit with a --no-color option (which does not exist). It
32 # overrides the suite.xml setting.
33 # Probably fix bug 29226
34 $command->arguments['colors'] = false;
37 # Makes MediaWiki PHPUnit directory includable so the PHPUnit will
38 # be able to resolve relative files inclusion such as suites/*
39 # PHPUnit uses stream_resolve_include_path() internally
40 # See bug 32022
41 set_include_path(
42 __DIR__
43 . PATH_SEPARATOR
44 . get_include_path()
47 $command->run( $_SERVER['argv'], $exit );
50 public function __call( $func, $args ) {
52 if ( substr( $func, -7 ) == 'Handler' ) {
53 if ( is_null( $args[0] ) ) {
54 $args[0] = true;
55 } //Booleans
56 self::$additionalOptions[substr( $func, 0, -7 )] = $args[0];
60 public function run( array $argv, $exit = true ) {
61 wfProfileIn( __METHOD__ );
63 $ret = parent::run( $argv, false );
65 wfProfileOut( __METHOD__ );
67 // Return to real wiki db, so profiling data is preserved
68 MediaWikiTestCase::teardownTestDB();
70 // Log profiling data, e.g. in the database or UDP
71 wfLogProfilingData();
73 if ( $exit ) {
74 exit( $ret );
75 } else {
76 return $ret;
80 public function showHelp() {
81 parent::showHelp();
83 print <<<EOT
85 ParserTest-specific options:
87 --regex="<regex>" Only run parser tests that match the given regex
88 --file="<filename>" File describing parser tests
89 --keep-uploads Re-use the same upload directory for each test, don't delete it
92 Database options:
93 --use-normal-tables Use normal DB tables.
94 --reuse-db Init DB only if tables are missing and keep after finish.
97 EOT;