More work on new parser tests:
authorX! <soxred93@users.mediawiki.org>
Sat, 1 Jan 2011 05:53:04 +0000 (05:53 +0000)
committerX! <soxred93@users.mediawiki.org>
Sat, 1 Jan 2011 05:53:04 +0000 (05:53 +0000)
-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
tests/phpunit/MediaWikiTestCase.php
tests/phpunit/includes/parser/NewParserHelpers.php
tests/phpunit/includes/parser/NewParserTest.php

index c7285f4..8a6665c 100644 (file)
@@ -1,19 +1,34 @@
 <?php
 
 class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {
-       static $additionalArgs = array( 'verbose' => 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];
+               }
        }
-
+       
 }
index c64f6d2..0134b3f 100644 (file)
@@ -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;
+               
+       }
 }
 
index 982d686..1a3bd25 100644 (file)
@@ -196,4 +196,4 @@ class ParserTestFileIterator implements Iterator {
 
                return false;
        }
-}
\ No newline at end of file
+}
index 1a939d8..68dd5e6 100644 (file)
@@ -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 );