Merge "Add pp_propname_page index to page_props"
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiPHPUnitCommand.php
1 <?php
2
3 class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {
4
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,
15 );
16
17 public function __construct() {
18 foreach ( self::$additionalOptions as $option => $default ) {
19 $this->longOptions[$option] = $option . 'Handler';
20 }
21
22 }
23
24 public static function main( $exit = true ) {
25 $command = new self;
26
27 if ( wfIsWindows() ) {
28 # Windows does not come anymore with ANSI.SYS loaded by default
29 # PHPUnit uses the suite.xml parameters to enable/disable colors
30 # which can be then forced to be enabled with --colors.
31 # The below code inject a parameter just like if the user called
32 # phpunit with a --no-color option (which does not exist). It
33 # overrides the suite.xml setting.
34 # Probably fix bug 29226
35 $command->arguments['colors'] = false;
36 }
37
38 # Makes MediaWiki PHPUnit directory includable so the PHPUnit will
39 # be able to resolve relative files inclusion such as suites/*
40 # PHPUnit uses stream_resolve_include_path() internally
41 # See bug 32022
42 set_include_path(
43 __DIR__
44 . PATH_SEPARATOR
45 . get_include_path()
46 );
47
48 $command->run( $_SERVER['argv'], $exit );
49 }
50
51 public function __call( $func, $args ) {
52
53 if ( substr( $func, -7 ) == 'Handler' ) {
54 if ( is_null( $args[0] ) ) {
55 $args[0] = true;
56 } //Booleans
57 self::$additionalOptions[substr( $func, 0, -7 )] = $args[0];
58 }
59 }
60
61 public function run( array $argv, $exit = true ) {
62 wfProfileIn( __METHOD__ );
63
64 $ret = parent::run( $argv, false );
65
66 wfProfileOut( __METHOD__ );
67
68 // Return to real wiki db, so profiling data is preserved
69 MediaWikiTestCase::teardownTestDB();
70
71 // Log profiling data, e.g. in the database or UDP
72 wfLogProfilingData();
73
74 if ( $exit ) {
75 exit( $ret );
76 } else {
77 return $ret;
78 }
79 }
80
81 public function showHelp() {
82 parent::showHelp();
83
84 print <<<EOT
85
86 ParserTest-specific options:
87
88 --regex="<regex>" Only run parser tests that match the given regex
89 --file="<filename>" Prints the version and exits.
90 --keep-uploads Re-use the same upload directory for each test, don't delete it
91
92
93 Database options:
94 --use-normal-tables Use normal DB tables.
95 --reuse-db Init DB only if tables are missing and keep after finish.
96
97
98 EOT;
99 }
100
101 }