summaryrefslogtreecommitdiff
path: root/tests/phpunit/MediaWikiPHPUnitCommand.php
blob: 12c2e0035c73ed9a59f77a7a0dcefbc54819f600 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php

class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {

	public static $additionalOptions = array(
		'regex=' => false,
		'file=' => false,
		'use-filebackend=' => false,
		'use-bagostuff=' => false,
		'use-jobqueue=' => false,
		'keep-uploads' => false,
		'use-normal-tables' => false,
		'reuse-db' => false,
		'wiki=' => false,
	);

	public function __construct() {
		foreach ( self::$additionalOptions as $option => $default ) {
			$this->longOptions[$option] = $option . 'Handler';
		}

	}

	public static function main( $exit = true ) {
		$command = new self;

		if ( wfIsWindows() ) {
			# Windows does not come anymore with ANSI.SYS loaded by default
			# PHPUnit uses the suite.xml parameters to enable/disable colors
			# which can be then forced to be enabled with --colors.
			# The below code inject a parameter just like if the user called
			# phpunit with a --no-color option (which does not exist). It
			# overrides the suite.xml setting.
			# Probably fix bug 29226
			$command->arguments['colors'] = false;
		}

		# Makes MediaWiki PHPUnit directory includable so the PHPUnit will
		# be able to resolve relative files inclusion such as suites/*
		# PHPUnit uses stream_resolve_include_path() internally
		# See bug 32022
		set_include_path(
			__DIR__
				. PATH_SEPARATOR
				. get_include_path()
		);

		$command->run( $_SERVER['argv'], $exit );
	}

	public function __call( $func, $args ) {

		if ( substr( $func, -7 ) == 'Handler' ) {
			if ( is_null( $args[0] ) ) {
				$args[0] = true;
			} //Booleans
			self::$additionalOptions[substr( $func, 0, -7 )] = $args[0];
		}
	}

	public function run( array $argv, $exit = true ) {
		wfProfileIn( __METHOD__ );

		$ret = parent::run( $argv, false );

		wfProfileOut( __METHOD__ );

		// Return to real wiki db, so profiling data is preserved
		MediaWikiTestCase::teardownTestDB();

		// Log profiling data, e.g. in the database or UDP
		wfLogProfilingData();

		if ( $exit ) {
			exit( $ret );
		} else {
			return $ret;
		}
	}

	public function showHelp() {
		parent::showHelp();

		print <<<EOT

ParserTest-specific options:

  --regex="<regex>"        Only run parser tests that match the given regex
  --file="<filename>"      Prints the version and exits.
  --keep-uploads           Re-use the same upload directory for each test, don't delete it


Database options:
  --use-normal-tables      Use normal DB tables.
  --reuse-db               Init DB only if tables are missing and keep after finish.


EOT;
	}

}