From f8d74604fd84b4c165a8147403f1f7b94da3ed46 Mon Sep 17 00:00:00 2001 From: X! Date: Sat, 1 Jan 2011 05:53:04 +0000 Subject: [PATCH] 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 --- tests/phpunit/MediaWikiPHPUnitCommand.php | 27 +++++++++++++---- tests/phpunit/MediaWikiTestCase.php | 14 +++++++++ .../includes/parser/NewParserHelpers.php | 2 +- .../phpunit/includes/parser/NewParserTest.php | 30 ++++++++++++++++--- 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/tests/phpunit/MediaWikiPHPUnitCommand.php b/tests/phpunit/MediaWikiPHPUnitCommand.php index c7285f4d93..8a6665c603 100644 --- a/tests/phpunit/MediaWikiPHPUnitCommand.php +++ b/tests/phpunit/MediaWikiPHPUnitCommand.php @@ -1,19 +1,34 @@ false ); + + static $additionalOptions = array( + 'regex=' => false, + 'record' => false, + 'file=' => false, + 'keep-uploads' => false, + ); + + //Fixme: These aren't shown on the --help menu public function __construct() { - $this->longOptions['verbose'] = 'verboseHandler'; + foreach( self::$additionalOptions as $option => $default ) { + $this->longOptions[$option] = $option . 'Handler'; + } + } public static function main( $exit = true ) { $command = new self; $command->run($_SERVER['argv'], $exit); } - - protected function verboseHandler($value) { - self::$additionalArgs['verbose'] = true; + + 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]; + } } - + } diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index c64f6d26e2..0134b3ffda 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -194,5 +194,19 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { throw new MWException( $this->db->getType() . " is not currently supported for unit testing." ); } } + + public function getCliArg( $offset ) { + + if( isset( MediaWikiPHPUnitCommand::$additionalOptions[$offset] ) ) { + return MediaWikiPHPUnitCommand::$additionalOptions[$offset]; + } + + } + + public function setCliArg( $offset, $value ) { + + MediaWikiPHPUnitCommand::$additionalOptions[$offset] = $value; + + } } diff --git a/tests/phpunit/includes/parser/NewParserHelpers.php b/tests/phpunit/includes/parser/NewParserHelpers.php index 982d686949..1a3bd25d3d 100644 --- a/tests/phpunit/includes/parser/NewParserHelpers.php +++ b/tests/phpunit/includes/parser/NewParserHelpers.php @@ -196,4 +196,4 @@ class ParserTestFileIterator implements Iterator { return false; } -} \ No newline at end of file +} diff --git a/tests/phpunit/includes/parser/NewParserTest.php b/tests/phpunit/includes/parser/NewParserTest.php index 1a939d8ef4..68dd5e6465 100644 --- a/tests/phpunit/includes/parser/NewParserTest.php +++ b/tests/phpunit/includes/parser/NewParserTest.php @@ -19,6 +19,24 @@ class NewParserTest extends MediaWikiTestCase { function setUp() { global $wgContLang; $wgContLang = Language::factory( 'en' ); + + + + //Setup CLI arguments + if ( $this->getCliArg( 'regex=' ) ) { + if ( $this->getCliArg( 'record' ) ) { + echo "Warning: --record cannot be used with --regex, disabling --record\n"; + $this->setCliArg( 'record', false ); + } + $this->regex = $this->getCliArg( 'regex=' ); + } else { + # Matches anything + $this->regex = ''; + } + + $this->keepUploads = $this->getCliArg( 'keep-uploads' ); + + global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList, $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, @@ -66,6 +84,7 @@ class NewParserTest extends MediaWikiTestCase { if ( $wgStyleDirectory === false ) { $wgStyleDirectory = "$IP/skins"; } + } /** @@ -273,12 +292,15 @@ class NewParserTest extends MediaWikiTestCase { public function testParserTests() { - //global $IP; - //$wgParserTestFiles = array( "$IP/tests/parser/testparserTests.txt" ); - global $wgParserTestFiles; - foreach( $wgParserTestFiles as $file ) { + $files = $wgParserTestFiles; + + if( $this->getCliArg( 'file=' ) ) { + $files = array( $this->getCliArg( 'file=' ) ); + } + + foreach( $files as $file ) { $iter = new ParserTestFileIterator( $file, $this ); -- 2.20.1