Merge "(bug 41476) Implement Language::isKnownLanguageTag()"
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiPHPUnitCommand.php
1 <?php
2
3 class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {
4
5 static $additionalOptions = array(
6 'regex=' => false,
7 'file=' => false,
8 'use-filebackend=' => false,
9 'use-bagostuff=' => false,
10 'keep-uploads' => false,
11 'use-normal-tables' => false,
12 'reuse-db' => false,
13 'wiki=' => false,
14 );
15
16 public function __construct() {
17 foreach( self::$additionalOptions as $option => $default ) {
18 $this->longOptions[$option] = $option . 'Handler';
19 }
20
21 }
22
23 public static function main( $exit = true ) {
24 $command = new self;
25
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;
35 }
36
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()
45 );
46
47 $command->run($_SERVER['argv'], $exit);
48 }
49
50 public function __call( $func, $args ) {
51
52 if( substr( $func, -7 ) == 'Handler' ) {
53 if( is_null( $args[0] ) ) $args[0] = true; //Booleans
54 self::$additionalOptions[substr( $func, 0, -7 ) ] = $args[0];
55 }
56 }
57
58 public function run( array $argv, $exit = true ) {
59 wfProfileIn( __METHOD__ );
60
61 $ret = parent::run( $argv, false );
62
63 wfProfileOut( __METHOD__ );
64
65 // Return to real wiki db, so profiling data is preserved
66 MediaWikiTestCase::teardownTestDB();
67
68 // Log profiling data, e.g. in the database or UDP
69 wfLogProfilingData();
70
71 if ( $exit ) {
72 exit( $ret );
73 } else {
74 return $ret;
75 }
76 }
77
78 public function showHelp() {
79 parent::showHelp();
80
81 print <<<EOT
82
83 ParserTest-specific options:
84
85 --regex="<regex>" Only run parser tests that match the given regex
86 --file="<filename>" Prints the version and exits.
87 --keep-uploads Re-use the same upload directory for each test, don't delete it
88
89
90 Database options:
91 --use-normal-tables Use normal DB tables.
92 --reuse-db Init DB only if tables are missing and keep after finish.
93
94
95 EOT;
96 }
97
98 }