f5760ea0d4771675dce44b9e9fa34c60df06a0f0
[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 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] ) ) {
54 $args[0] = true;
55 } //Booleans
56 self::$additionalOptions[substr( $func, 0, -7 )] = $args[0];
57 }
58 }
59
60 public function run( array $argv, $exit = true ) {
61 wfProfileIn( __METHOD__ );
62
63 $ret = parent::run( $argv, false );
64
65 wfProfileOut( __METHOD__ );
66
67 // Return to real wiki db, so profiling data is preserved
68 MediaWikiTestCase::teardownTestDB();
69
70 // Log profiling data, e.g. in the database or UDP
71 wfLogProfilingData();
72
73 if ( $exit ) {
74 exit( $ret );
75 } else {
76 return $ret;
77 }
78 }
79
80 public function showHelp() {
81 parent::showHelp();
82
83 print <<<EOT
84
85 ParserTest-specific options:
86
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
90
91
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.
95
96
97 EOT;
98 }
99 }