Rename TestFileIterator $parser member. It is unrelated with the Parser object.
authorPlatonides <platonides@users.mediawiki.org>
Fri, 5 Nov 2010 22:14:45 +0000 (22:14 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Fri, 5 Nov 2010 22:14:45 +0000 (22:14 +0000)
Too much similar names here. What do you drink with your articles? A ParserTest
or a MediaWikiParserTest?

Removed the redundant setParser() method.

maintenance/tests/phpunit/includes/parser/MediaWikiParserTest.php
maintenance/tests/testHelpers.inc

index a8d105a..3825a8f 100644 (file)
@@ -20,8 +20,7 @@ class MediaWikiParserTest extends MediaWikiTestSetup {
 
                $tester = new self;
 
-               $iter = new TestFileIterator( "$IP/maintenance/tests/parser/parserTests.txt" );
-               $iter->setParser( $tester );
+               $iter = new TestFileIterator( "$IP/maintenance/tests/parser/parserTests.txt", $tester );
                $tester->count = 0;
 
                foreach ( $iter as $test ) {
@@ -66,5 +65,9 @@ class MediaWikiParserTest extends MediaWikiTestSetup {
        public function addArticle( $name, $text, $line ) {
                $this->articles[$name] = $text;
        }
+
+       public function showRunFile( $path ) {
+               /* Nothing shown when run from phpunit */
+       }
 }
 
index 71479e5..24172e4 100644 (file)
@@ -453,13 +453,13 @@ class RemoteTestRecorder extends TestRecorder {
 class TestFileIterator implements Iterator {
        private $file;
        private $fh;
-       private $parser;
+       private $parserTest; /* An instance of ParserTest (parserTests.php) or MediaWikiParserTest (phpunit) */
        private $index = 0;
        private $test;
        private $lineNum;
        private $eof;
 
-       function __construct( $file, $parser = null ) {
+       function __construct( $file, $parserTest = null ) {
                global $IP;
 
                $this->file = $file;
@@ -469,19 +469,15 @@ class TestFileIterator implements Iterator {
                        wfDie( "Couldn't open file '$file'\n" );
                }
 
-               $this->parser = $parser;
+               $this->parserTest = $parserTest;
 
-               if ( $this->parser ) {
-                       $this->parser->showRunFile( wfRelativePath( $this->file, $IP ) );
+               if ( $this->parserTest ) {
+                       $this->parserTest->showRunFile( wfRelativePath( $this->file, $IP ) );
                }
 
                $this->lineNum = $this->index = 0;
        }
 
-       function setParser( MediaWikiParserTest $parser ) {
-               $this->parser = $parser;
-       }
-
        function rewind() {
                if ( fseek( $this->fh, 0 ) ) {
                        wfDie( "Couldn't fseek to the start of '$this->file'\n" );
@@ -536,9 +532,9 @@ class TestFileIterator implements Iterator {
                                                wfDie( "'endarticle' without 'article' at line {$this->lineNum} of $this->file\n" );
                                        }
 
-                                       if ( $this->parser ) {
-                                               $this->parser->addArticle( ParserTest::chomp( $data['article'] ), $data['text'], $this->lineNum );
-                                       } else {
+                                       if ( $this->parserTest ) {
+                                               $this->parserTest->addArticle( ParserTest::chomp( $data['article'] ), $data['text'], $this->lineNum );
+                                       } else {wfDie("JAJA");
                                                ParserTest::addArticle( $data['article'], $data['text'], $this->lineNum );
                                        }
                                        $data = array();
@@ -556,7 +552,7 @@ class TestFileIterator implements Iterator {
                                                $line = trim( $line );
 
                                                if ( $line ) {
-                                                       if ( $this->parser && !$this->parser->requireHook( $line ) ) {
+                                                       if ( $this->parserTest && !$this->parserTest->requireHook( $line ) ) {
                                                                return false;
                                                        }
                                                }
@@ -577,7 +573,7 @@ class TestFileIterator implements Iterator {
                                                $line = trim( $line );
 
                                                if ( $line ) {
-                                                       if ( $this->parser && !$this->parser->requireFunctionHook( $line ) ) {
+                                                       if ( $this->parserTest && !$this->parserTest->requireFunctionHook( $line ) ) {
                                                                return false;
                                                        }
                                                }
@@ -609,9 +605,9 @@ class TestFileIterator implements Iterator {
                                        if ( !isset( $data['config'] ) )
                                                $data['config'] = '';
 
-                                       if ( $this->parser
-                                                && ( ( preg_match( '/\\bdisabled\\b/i', $data['options'] ) && !$this->parser->runDisabled )
-                                                        || !preg_match( "/" . $this->parser->regex . "/i", $data['test'] ) )  ) {
+                                       if ( $this->parserTest
+                                                && ( ( preg_match( '/\\bdisabled\\b/i', $data['options'] ) && !$this->parserTest->runDisabled )
+                                                        || !preg_match( "/" . $this->parserTest->regex . "/i", $data['test'] ) )  ) {
                                                # disabled test
                                                $data = array();
                                                $section = null;
@@ -621,7 +617,7 @@ class TestFileIterator implements Iterator {
 
                                        global $wgUseTeX;
 
-                                       if ( $this->parser &&
+                                       if ( $this->parserTest &&
                                                 preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) {
                                                # don't run math tests if $wgUseTeX is set to false in LocalSettings
                                                $data = array();
@@ -630,7 +626,7 @@ class TestFileIterator implements Iterator {
                                                continue;
                                        }
 
-                                       if ( $this->parser ) {
+                                       if ( $this->parserTest ) {
                                                $this->test = array(
                                                        'test' => ParserTest::chomp( $data['test'] ),
                                                        'input' => ParserTest::chomp( $data['input'] ),