Merge "Tweaked location of profiling in query() to split out the implicit BEGIN"
[mediawiki.git] / tests / phpunit / MediaWikiPHPUnitCommand.php
blob387107ba915a2f523b726ffda02e56dbf909a3a1
1 <?php
3 class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {
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,
18 public function __construct() {
19 foreach ( self::$additionalOptions as $option => $default ) {
20 $this->longOptions[$option] = $option . 'Handler';
24 protected function handleArguments(array $argv) {
25 parent::handleArguments( $argv );
27 if ( !isset( $this->arguments['listeners'] ) ) {
28 $this->arguments['listeners'] = array();
31 foreach ($this->options[0] as $option) {
32 switch ($option[0]) {
33 case '--debug-tests':
34 $this->arguments['listeners'][] = new MediaWikiPHPUnitTestListener( 'PHPUnitCommand' );
35 break;
40 public static function main( $exit = true ) {
41 $command = new self;
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;
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()
64 $command->run( $_SERVER['argv'], $exit );
67 public function __call( $func, $args ) {
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];
77 public function run( array $argv, $exit = true ) {
78 wfProfileIn( __METHOD__ );
80 $ret = parent::run( $argv, false );
82 wfProfileOut( __METHOD__ );
84 // Return to real wiki db, so profiling data is preserved
85 MediaWikiTestCase::teardownTestDB();
87 // Log profiling data, e.g. in the database or UDP
88 wfLogProfilingData();
90 if ( $exit ) {
91 exit( $ret );
92 } else {
93 return $ret;
97 public function showHelp() {
98 parent::showHelp();
100 print <<<EOT
102 ParserTest-specific options:
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
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.
114 Debugging options:
115 --debug-tests Log testing activity to the PHPUnitCommand log channel.
117 EOT;