Merge branch 'Wikidata' of ssh://gerrit.wikimedia.org:29418/mediawiki/core into Wikidata
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiPHPUnitCommand.php
1 <?php
2
3 class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {
4
5 static $additionalOptions = array(
6 'regex=' => false,
7 'file=' => false,
8 'use-filebackend=' => false,
9 'keep-uploads' => false,
10 'use-normal-tables' => false,
11 'reuse-db' => false,
12 );
13
14 public function __construct() {
15 foreach( self::$additionalOptions as $option => $default ) {
16 $this->longOptions[$option] = $option . 'Handler';
17 }
18
19 }
20
21 public static function main( $exit = true ) {
22 $command = new self;
23
24 if( wfIsWindows() ) {
25 # Windows does not come anymore with ANSI.SYS loaded by default
26 # PHPUnit uses the suite.xml parameters to enable/disable colors
27 # which can be then forced to be enabled with --colors.
28 # The below code inject a parameter just like if the user called
29 # phpunit with a --no-color option (which does not exist). It
30 # overrides the suite.xml setting.
31 # Probably fix bug 29226
32 $command->arguments['colors'] = false;
33 }
34
35 # Makes MediaWiki PHPUnit directory includable so the PHPUnit will
36 # be able to resolve relative files inclusion such as suites/*
37 # PHPUnit uses stream_resolve_include_path() internally
38 # See bug 32022
39 set_include_path(
40 dirname( __FILE__ )
41 .PATH_SEPARATOR
42 . get_include_path()
43 );
44
45 $command->run($_SERVER['argv'], $exit);
46 }
47
48 public function __call( $func, $args ) {
49
50 if( substr( $func, -7 ) == 'Handler' ) {
51 if( is_null( $args[0] ) ) $args[0] = true; //Booleans
52 self::$additionalOptions[substr( $func, 0, -7 ) ] = $args[0];
53 }
54 }
55
56 protected function handleCustomTestSuite() {
57 if ( empty( $this->arguments['printer'] ) ) {
58 $this->arguments['printer'] = new PHPUnit_TextUI_ResultPrinter(
59 null,
60 isset($this->arguments['verbose']) ? $this->arguments['verbose'] : false,
61 isset($this->arguments['colors']) ? $this->arguments['colors'] : true,
62 isset($this->arguments['debug']) ? $this->arguments['debug'] : false
63 );
64 }
65
66 parent::handleCustomTestSuite();
67 }
68
69 public function showHelp() {
70 parent::showHelp();
71
72 print <<<EOT
73
74 ParserTest-specific options:
75
76 --regex="<regex>" Only run parser tests that match the given regex
77 --file="<filename>" Prints the version and exits.
78 --keep-uploads Re-use the same upload directory for each test, don't delete it
79
80
81 Database options:
82 --use-normal-tables Use normal DB tables.
83 --reuse-db Init DB only if tables are missing and keep after finish.
84
85
86 EOT;
87 }
88
89 }
90
91 class MediaWikiPHPUnitResultPrinter extends PHPUnit_TextUI_ResultPrinter {
92 /**
93 * Overrides original method to ignore incomplete tests except in verbose mode.
94 *
95 * @param PHPUnit_Framework_TestResult $result
96 */
97 protected function printIncompletes(PHPUnit_Framework_TestResult $result)
98 {
99 if ( $this->verbose ) {
100 parent::printIncompletes( $result );
101 }
102 }
103
104 /**
105 * Overrides original method to ignore skipped tests except in verbose mode.
106 *
107 * @param PHPUnit_Framework_TestResult $result
108 */
109 protected function printSkipped(PHPUnit_Framework_TestResult $result)
110 {
111 if ( $this->verbose ) {
112 parent::printSkipped( $result );
113 }
114 }
115
116 }