Remove color opt setting from MediaWikiPHPUnitCommand
[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 'debug-tests' => false,
16 );
17
18 public function __construct() {
19 foreach ( self::$additionalOptions as $option => $default ) {
20 $this->longOptions[$option] = $option . 'Handler';
21 }
22 }
23
24 protected function handleArguments( array $argv ) {
25 parent::handleArguments( $argv );
26
27 if ( !isset( $this->arguments['listeners'] ) ) {
28 $this->arguments['listeners'] = array();
29 }
30
31 foreach ( $this->options[0] as $option ) {
32 switch ( $option[0] ) {
33 case '--debug-tests':
34 $this->arguments['listeners'][] = new MediaWikiPHPUnitTestListener( 'PHPUnitCommand' );
35 break;
36 }
37 }
38 }
39
40 public static function main( $exit = true ) {
41 $command = new self;
42
43 # Makes MediaWiki PHPUnit directory includable so the PHPUnit will
44 # be able to resolve relative files inclusion such as suites/*
45 # PHPUnit uses stream_resolve_include_path() internally
46 # See bug 32022
47 set_include_path(
48 __DIR__
49 . PATH_SEPARATOR
50 . get_include_path()
51 );
52
53 $command->run( $_SERVER['argv'], $exit );
54 }
55
56 public function __call( $func, $args ) {
57
58 if ( substr( $func, -7 ) == 'Handler' ) {
59 if ( is_null( $args[0] ) ) {
60 $args[0] = true;
61 } //Booleans
62 self::$additionalOptions[substr( $func, 0, -7 )] = $args[0];
63 }
64 }
65
66 public function run( array $argv, $exit = true ) {
67 wfProfileIn( __METHOD__ );
68
69 $ret = parent::run( $argv, false );
70
71 wfProfileOut( __METHOD__ );
72
73 // Return to real wiki db, so profiling data is preserved
74 MediaWikiTestCase::teardownTestDB();
75
76 // Log profiling data, e.g. in the database or UDP
77 wfLogProfilingData();
78
79 if ( $exit ) {
80 exit( $ret );
81 } else {
82 return $ret;
83 }
84 }
85
86 public function showHelp() {
87 parent::showHelp();
88
89 print <<<EOT
90
91 ParserTest-specific options:
92 --regex="<regex>" Only run parser tests that match the given regex
93 --file="<filename>" File describing parser tests
94 --keep-uploads Re-use the same upload directory for each test, don't delete it
95
96 Database options:
97 --use-normal-tables Use normal DB tables.
98 --reuse-db Init DB only if tables are missing and keep after finish.
99
100 Debugging options:
101 --debug-tests Log testing activity to the PHPUnitCommand log channel.
102
103 EOT;
104 }
105 }