Fix spacing and break some lines
[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 if ( wfIsWindows() ) {
44 # Windows does not come anymore with ANSI.SYS loaded by default
45 # PHPUnit uses the suite.xml parameters to enable/disable colors
46 # which can be then forced to be enabled with --colors.
47 # The below code inject a parameter just like if the user called
48 # phpunit with a --no-color option (which does not exist). It
49 # overrides the suite.xml setting.
50 # Probably fix bug 29226
51 $command->arguments['colors'] = false;
52 }
53
54 # Makes MediaWiki PHPUnit directory includable so the PHPUnit will
55 # be able to resolve relative files inclusion such as suites/*
56 # PHPUnit uses stream_resolve_include_path() internally
57 # See bug 32022
58 set_include_path(
59 __DIR__
60 . PATH_SEPARATOR
61 . get_include_path()
62 );
63
64 $command->run( $_SERVER['argv'], $exit );
65 }
66
67 public function __call( $func, $args ) {
68
69 if ( substr( $func, -7 ) == 'Handler' ) {
70 if ( is_null( $args[0] ) ) {
71 $args[0] = true;
72 } //Booleans
73 self::$additionalOptions[substr( $func, 0, -7 )] = $args[0];
74 }
75 }
76
77 public function run( array $argv, $exit = true ) {
78 wfProfileIn( __METHOD__ );
79
80 $ret = parent::run( $argv, false );
81
82 wfProfileOut( __METHOD__ );
83
84 // Return to real wiki db, so profiling data is preserved
85 MediaWikiTestCase::teardownTestDB();
86
87 // Log profiling data, e.g. in the database or UDP
88 wfLogProfilingData();
89
90 if ( $exit ) {
91 exit( $ret );
92 } else {
93 return $ret;
94 }
95 }
96
97 public function showHelp() {
98 parent::showHelp();
99
100 print <<<EOT
101
102 ParserTest-specific options:
103
104 --regex="<regex>" Only run parser tests that match the given regex
105 --file="<filename>" File describing parser tests
106 --keep-uploads Re-use the same upload directory for each test, don't delete it
107
108
109 Database options:
110 --use-normal-tables Use normal DB tables.
111 --reuse-db Init DB only if tables are missing and keep after finish.
112
113
114 Debugging options:
115 --debug-tests Log testing activity to the PHPUnitCommand log channel.
116
117 EOT;
118 }
119 }