r79413 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79412‎ | r79413 | r79414 >
Date:05:53, 1 January 2011
Author:soxred93
Status:ok
Tags:
Comment:
More work on new parser tests:
-No need to specify a new function for each argument, use PHP5 magic to automatically set it
-Create (g|s)etCliArg() functions
-Implement some features from the old parser tests
Modified paths:
  • /trunk/phase3/tests/phpunit/MediaWikiPHPUnitCommand.php (modified) (history)
  • /trunk/phase3/tests/phpunit/MediaWikiTestCase.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/parser/NewParserHelpers.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/MediaWikiPHPUnitCommand.php
@@ -1,19 +1,34 @@
22 <?php
33
44 class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {
5 - static $additionalArgs = array( 'verbose' => false );
 5+
 6+ static $additionalOptions = array(
 7+ 'regex=' => false,
 8+ 'record' => false,
 9+ 'file=' => false,
 10+ 'keep-uploads' => false,
 11+ );
 12+
 13+ //Fixme: These aren't shown on the --help menu
614
715 public function __construct() {
8 - $this->longOptions['verbose'] = 'verboseHandler';
 16+ foreach( self::$additionalOptions as $option => $default ) {
 17+ $this->longOptions[$option] = $option . 'Handler';
 18+ }
 19+
920 }
1021
1122 public static function main( $exit = true ) {
1223 $command = new self;
1324 $command->run($_SERVER['argv'], $exit);
1425 }
15 -
16 - protected function verboseHandler($value) {
17 - self::$additionalArgs['verbose'] = true;
 26+
 27+ public function __call( $func, $args ) {
 28+
 29+ if( substr( $func, -7 ) == 'Handler' ) {
 30+ if( is_null( $args[0] ) ) $args[0] = true; //Booleans
 31+ self::$additionalOptions[substr( $func, 0, -7 ) ] = $args[0];
 32+ }
1833 }
19 -
 34+
2035 }
Index: trunk/phase3/tests/phpunit/MediaWikiTestCase.php
@@ -194,5 +194,19 @@
195195 throw new MWException( $this->db->getType() . " is not currently supported for unit testing." );
196196 }
197197 }
 198+
 199+ public function getCliArg( $offset ) {
 200+
 201+ if( isset( MediaWikiPHPUnitCommand::$additionalOptions[$offset] ) ) {
 202+ return MediaWikiPHPUnitCommand::$additionalOptions[$offset];
 203+ }
 204+
 205+ }
 206+
 207+ public function setCliArg( $offset, $value ) {
 208+
 209+ MediaWikiPHPUnitCommand::$additionalOptions[$offset] = $value;
 210+
 211+ }
198212 }
199213
Index: trunk/phase3/tests/phpunit/includes/parser/NewParserHelpers.php
@@ -196,4 +196,4 @@
197197
198198 return false;
199199 }
200 -}
\ No newline at end of file
 200+}
Index: trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php
@@ -19,7 +19,25 @@
2020 function setUp() {
2121 global $wgContLang;
2222 $wgContLang = Language::factory( 'en' );
 23+
 24+
 25+
 26+ //Setup CLI arguments
 27+ if ( $this->getCliArg( 'regex=' ) ) {
 28+ if ( $this->getCliArg( 'record' ) ) {
 29+ echo "Warning: --record cannot be used with --regex, disabling --record\n";
 30+ $this->setCliArg( 'record', false );
 31+ }
 32+ $this->regex = $this->getCliArg( 'regex=' );
 33+ } else {
 34+ # Matches anything
 35+ $this->regex = '';
 36+ }
 37+
 38+ $this->keepUploads = $this->getCliArg( 'keep-uploads' );
2339
 40+
 41+
2442 global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
2543 $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
2644 $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc,
@@ -66,6 +84,7 @@
6785 if ( $wgStyleDirectory === false ) {
6886 $wgStyleDirectory = "$IP/skins";
6987 }
 88+
7089 }
7190
7291 /**
@@ -273,12 +292,15 @@
274293
275294 public function testParserTests() {
276295
277 - //global $IP;
278 - //$wgParserTestFiles = array( "$IP/tests/parser/testparserTests.txt" );
279 -
280296 global $wgParserTestFiles;
281297
282 - foreach( $wgParserTestFiles as $file ) {
 298+ $files = $wgParserTestFiles;
 299+
 300+ if( $this->getCliArg( 'file=' ) ) {
 301+ $files = array( $this->getCliArg( 'file=' ) );
 302+ }
 303+
 304+ foreach( $files as $file ) {
283305
284306 $iter = new ParserTestFileIterator( $file, $this );
285307

Status & tagging log