r76149 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76148‎ | r76149 | r76150 >
Date:22:14, 5 November 2010
Author:platonides
Status:deferred
Tags:
Comment:
Rename TestFileIterator $parser member. It is unrelated with the Parser object.
Too much similar names here. What do you drink with your articles? A ParserTest
or a MediaWikiParserTest?

Removed the redundant setParser() method.
Modified paths:
  • /trunk/phase3/maintenance/tests/phpunit/includes/parser/MediaWikiParserTest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/testHelpers.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/phpunit/includes/parser/MediaWikiParserTest.php
@@ -20,8 +20,7 @@
2121
2222 $tester = new self;
2323
24 - $iter = new TestFileIterator( "$IP/maintenance/tests/parser/parserTests.txt" );
25 - $iter->setParser( $tester );
 24+ $iter = new TestFileIterator( "$IP/maintenance/tests/parser/parserTests.txt", $tester );
2625 $tester->count = 0;
2726
2827 foreach ( $iter as $test ) {
@@ -66,5 +65,9 @@
6766 public function addArticle( $name, $text, $line ) {
6867 $this->articles[$name] = $text;
6968 }
 69+
 70+ public function showRunFile( $path ) {
 71+ /* Nothing shown when run from phpunit */
 72+ }
7073 }
7174
Index: trunk/phase3/maintenance/tests/testHelpers.inc
@@ -453,13 +453,13 @@
454454 class TestFileIterator implements Iterator {
455455 private $file;
456456 private $fh;
457 - private $parser;
 457+ private $parserTest; /* An instance of ParserTest (parserTests.php) or MediaWikiParserTest (phpunit) */
458458 private $index = 0;
459459 private $test;
460460 private $lineNum;
461461 private $eof;
462462
463 - function __construct( $file, $parser = null ) {
 463+ function __construct( $file, $parserTest = null ) {
464464 global $IP;
465465
466466 $this->file = $file;
@@ -469,19 +469,15 @@
470470 wfDie( "Couldn't open file '$file'\n" );
471471 }
472472
473 - $this->parser = $parser;
 473+ $this->parserTest = $parserTest;
474474
475 - if ( $this->parser ) {
476 - $this->parser->showRunFile( wfRelativePath( $this->file, $IP ) );
 475+ if ( $this->parserTest ) {
 476+ $this->parserTest->showRunFile( wfRelativePath( $this->file, $IP ) );
477477 }
478478
479479 $this->lineNum = $this->index = 0;
480480 }
481481
482 - function setParser( MediaWikiParserTest $parser ) {
483 - $this->parser = $parser;
484 - }
485 -
486482 function rewind() {
487483 if ( fseek( $this->fh, 0 ) ) {
488484 wfDie( "Couldn't fseek to the start of '$this->file'\n" );
@@ -536,9 +532,9 @@
537533 wfDie( "'endarticle' without 'article' at line {$this->lineNum} of $this->file\n" );
538534 }
539535
540 - if ( $this->parser ) {
541 - $this->parser->addArticle( ParserTest::chomp( $data['article'] ), $data['text'], $this->lineNum );
542 - } else {
 536+ if ( $this->parserTest ) {
 537+ $this->parserTest->addArticle( ParserTest::chomp( $data['article'] ), $data['text'], $this->lineNum );
 538+ } else {wfDie("JAJA");
543539 ParserTest::addArticle( $data['article'], $data['text'], $this->lineNum );
544540 }
545541 $data = array();
@@ -556,7 +552,7 @@
557553 $line = trim( $line );
558554
559555 if ( $line ) {
560 - if ( $this->parser && !$this->parser->requireHook( $line ) ) {
 556+ if ( $this->parserTest && !$this->parserTest->requireHook( $line ) ) {
561557 return false;
562558 }
563559 }
@@ -577,7 +573,7 @@
578574 $line = trim( $line );
579575
580576 if ( $line ) {
581 - if ( $this->parser && !$this->parser->requireFunctionHook( $line ) ) {
 577+ if ( $this->parserTest && !$this->parserTest->requireFunctionHook( $line ) ) {
582578 return false;
583579 }
584580 }
@@ -609,9 +605,9 @@
610606 if ( !isset( $data['config'] ) )
611607 $data['config'] = '';
612608
613 - if ( $this->parser
614 - && ( ( preg_match( '/\\bdisabled\\b/i', $data['options'] ) && !$this->parser->runDisabled )
615 - || !preg_match( "/" . $this->parser->regex . "/i", $data['test'] ) ) ) {
 609+ if ( $this->parserTest
 610+ && ( ( preg_match( '/\\bdisabled\\b/i', $data['options'] ) && !$this->parserTest->runDisabled )
 611+ || !preg_match( "/" . $this->parserTest->regex . "/i", $data['test'] ) ) ) {
616612 # disabled test
617613 $data = array();
618614 $section = null;
@@ -621,7 +617,7 @@
622618
623619 global $wgUseTeX;
624620
625 - if ( $this->parser &&
 621+ if ( $this->parserTest &&
626622 preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) {
627623 # don't run math tests if $wgUseTeX is set to false in LocalSettings
628624 $data = array();
@@ -630,7 +626,7 @@
631627 continue;
632628 }
633629
634 - if ( $this->parser ) {
 630+ if ( $this->parserTest ) {
635631 $this->test = array(
636632 'test' => ParserTest::chomp( $data['test'] ),
637633 'input' => ParserTest::chomp( $data['input'] ),

Follow-up revisions

RevisionCommit summaryAuthorDate
r82877Remove NewParserHelpers.php and use instead the original TestFileIterator fro...platonides23:45, 26 February 2011

Status & tagging log