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