Move teardownTestDB and wfLogProfilingData out of MWPHPUnitCommand
[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 $command->run( $_SERVER['argv'], $exit );
43 }
44
45 public function __call( $func, $args ) {
46
47 if ( substr( $func, -7 ) == 'Handler' ) {
48 if ( is_null( $args[0] ) ) {
49 $args[0] = true;
50 } //Booleans
51 self::$additionalOptions[substr( $func, 0, -7 )] = $args[0];
52 }
53 }
54
55 public function run( array $argv, $exit = true ) {
56 wfProfileIn( __METHOD__ );
57
58 $ret = parent::run( $argv, false );
59
60 wfProfileOut( __METHOD__ );
61
62 if ( $exit ) {
63 exit( $ret );
64 } else {
65 return $ret;
66 }
67 }
68
69 public function showHelp() {
70 parent::showHelp();
71
72 print <<<EOT
73
74 ParserTest-specific options:
75 --regex="<regex>" Only run parser tests that match the given regex
76 --file="<filename>" File describing parser tests
77 --keep-uploads Re-use the same upload directory for each test, don't delete it
78
79 Database options:
80 --use-normal-tables Use normal DB tables.
81 --reuse-db Init DB only if tables are missing and keep after finish.
82
83 Debugging options:
84 --debug-tests Log testing activity to the PHPUnitCommand log channel.
85
86 EOT;
87 }
88 }