From df29a359f85e31726e929ac22ebe6eb10b6ac9f9 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Thu, 8 Sep 2016 11:07:06 +1000 Subject: [PATCH] Renames preparatory to parser tests refactor Since in several cases, with an all-in-one commit, git's file rename detection failed, I split the renames out into their own commit to make review easier. Some changes here won't make complete sense without the following commit. * Moved TestsAutoLoader to tests/common/. It will be joined by a friend. * Renamed ParserTest to ParserTestRunner, since the former name was overly generic. * Renamed TestFileIterator to TestFileReader. Please see the subsequent commit for rationale. * Moved parserTests.php to tests/parser/. It was the only file left in tests/, and it should have been moved to tests/parser years ago, analogous to phpunit.php. * Renamed NewParserTest to ParserIntegrationTest. This was a tricky one, apparently the name has to end in "Test" or else the structure test will fail. Analogous to ParserMethodsTest etc. Rationale: because it's not new anymore. * Renamed MediaWikiParserTest to ParserTestTopLevelSuite and moved it to the suites directory. A more descriptive name. Being in suites/ shields it from StructureTests, and is correct anyway. Change-Id: Iddc6eaf815fdd64b3addb8570b4b6303ab99d634 --- includes/parser/Parser.php | 2 +- maintenance/Makefile | 2 +- maintenance/checkLess.php | 2 +- tests/{ => common}/TestsAutoLoader.php | 12 +++++++----- tests/parser/DelayedParserTest.php | 16 +++++++++------- .../{ParserTest.php => ParserTestRunner.php} | 10 +++++----- tests/parser/TestFileDataProvider.php | 4 ++-- ...TestFileIterator.php => TestFileReader.php} | 18 +++++++++--------- tests/parser/fuzzTest.php | 4 ++-- tests/{ => parser}/parserTests.php | 6 +++--- ...arserTest.php => ParserIntegrationTest.php} | 16 ++++++++-------- tests/phpunit/phpunit.php | 2 +- tests/phpunit/suite.xml | 2 +- .../suites/ExtensionsParserTestSuite.php | 2 +- .../ParserTestTopLevelSuite.php} | 14 +++++++------- 15 files changed, 58 insertions(+), 54 deletions(-) rename tests/{ => common}/TestsAutoLoader.php (95%) rename tests/parser/{ParserTest.php => ParserTestRunner.php} (99%) rename tests/parser/{TestFileIterator.php => TestFileReader.php} (93%) rename tests/{ => parser}/parserTests.php (95%) rename tests/phpunit/includes/parser/{NewParserTest.php => ParserIntegrationTest.php} (98%) rename tests/phpunit/{includes/parser/MediaWikiParserTest.php => suites/ParserTestTopLevelSuite.php} (89%) diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index b53920b0fc..d83ea34efd 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -1775,7 +1775,7 @@ class Parser { * Replace external links (REL) * * Note: this is all very hackish and the order of execution matters a lot. - * Make sure to run tests/parserTests.php if you change this code. + * Make sure to run tests/parser/parserTests.php if you change this code. * * @private * diff --git a/maintenance/Makefile b/maintenance/Makefile index 2555475102..a348e856f3 100644 --- a/maintenance/Makefile +++ b/maintenance/Makefile @@ -4,7 +4,7 @@ help: @echo "Run 'make man' to run the doxygen generation with man pages." test: - php tests/parserTests.php --quiet + php tests/parser/parserTests.php --quiet doc: php mwdocgen.php --all diff --git a/maintenance/checkLess.php b/maintenance/checkLess.php index eeec9d1c89..df1868eb47 100644 --- a/maintenance/checkLess.php +++ b/maintenance/checkLess.php @@ -40,7 +40,7 @@ class CheckLess extends Maintenance { // NOTE (phuedx, 2014-03-26) wgAutoloadClasses isn't set up // by either of the dependencies at the top of the file, so // require it here. - require_once __DIR__ . '/../tests/TestsAutoLoader.php'; + require_once __DIR__ . '/../tests/common/TestsAutoLoader.php'; // If phpunit isn't available by autoloader try pulling it in if ( !class_exists( 'PHPUnit_Framework_TestCase' ) ) { diff --git a/tests/TestsAutoLoader.php b/tests/common/TestsAutoLoader.php similarity index 95% rename from tests/TestsAutoLoader.php rename to tests/common/TestsAutoLoader.php index 4858703b92..7de339472d 100644 --- a/tests/TestsAutoLoader.php +++ b/tests/common/TestsAutoLoader.php @@ -22,7 +22,7 @@ */ global $wgAutoloadClasses; -$testDir = __DIR__; +$testDir = __DIR__ . '/..'; $wgAutoloadClasses += [ @@ -135,14 +135,13 @@ $wgAutoloadClasses += [ 'DelayedParserTest' => "$testDir/parser/DelayedParserTest.php", 'DjVuSupport' => "$testDir/parser/DjVuSupport.php", 'ITestRecorder' => "$testDir/parser/ITestRecorder.php", - 'MediaWikiParserTest' => "$testDir/phpunit/includes/parser/MediaWikiParserTest.php", - 'NewParserTest' => "$testDir/phpunit/includes/parser/NewParserTest.php", - 'ParserTest' => "$testDir/parser/ParserTest.php", + 'ParserIntegrationTest' => "$testDir/phpunit/includes/parser/ParserIntegrationTest.php", + 'ParserTestRunner' => "$testDir/parser/ParserTestRunner.php", 'ParserTestParserHook' => "$testDir/parser/ParserTestParserHook.php", 'ParserTestResult' => "$testDir/parser/ParserTestResult.php", 'ParserTestResultNormalizer' => "$testDir/parser/ParserTestResultNormalizer.php", 'TestFileDataProvider' => "$testDir/parser/TestFileDataProvider.php", - 'TestFileIterator' => "$testDir/parser/TestFileIterator.php", + 'TestFileReader' => "$testDir/parser/TestFileReader.php", 'TestRecorder' => "$testDir/parser/TestRecorder.php", 'TidySupport' => "$testDir/parser/TidySupport.php", @@ -152,4 +151,7 @@ $wgAutoloadClasses += [ # tests/phpunit/includes/specialpage 'SpecialPageTestHelper' => "$testDir/phpunit/includes/specialpage/SpecialPageTestHelper.php", + + # tests/phpunit/suites + 'ParserTestTopLevelSuite' => "$testDir/phpunit/suites/ParserTestTopLevelSuite.php", ]; diff --git a/tests/parser/DelayedParserTest.php b/tests/parser/DelayedParserTest.php index 1c5c36bf0e..f9ece9295b 100644 --- a/tests/parser/DelayedParserTest.php +++ b/tests/parser/DelayedParserTest.php @@ -47,14 +47,16 @@ class DelayedParserTest { /** * Called whenever we actually want to run the hook. * Should be the case if we found the parserTest is not disabled - * @param ParserTest|NewParserTest $parserTest + * @param ParserTestRunner|ParserIntegrationTest $parserTest * @return bool * @throws MWException */ public function unleash( &$parserTest ) { - if ( !( $parserTest instanceof ParserTest || $parserTest instanceof NewParserTest ) ) { - throw new MWException( __METHOD__ . " must be passed an instance of ParserTest or " - . "NewParserTest classes\n" ); + if ( !( $parserTest instanceof ParserTestRunner + || $parserTest instanceof ParserIntegrationTest ) + ) { + throw new MWException( __METHOD__ . " must be passed an instance of " . + "ParserTestRunner or ParserIntegrationTest classes\n" ); } # Trigger delayed hooks. Any failure will make us abort @@ -86,7 +88,7 @@ class DelayedParserTest { } /** - * Similar to ParserTest object but does not run anything + * Similar to ParserTestRunner object but does not run anything * Use unleash() to really execute the hook * @param string $hook */ @@ -95,7 +97,7 @@ class DelayedParserTest { } /** - * Similar to ParserTest object but does not run anything + * Similar to ParserTestRunner object but does not run anything * Use unleash() to really execute the hook function * @param string $fnHook */ @@ -104,7 +106,7 @@ class DelayedParserTest { } /** - * Similar to ParserTest object but does not run anything + * Similar to ParserTestRunner object but does not run anything * Use unleash() to really execute the hook function * @param string $hook */ diff --git a/tests/parser/ParserTest.php b/tests/parser/ParserTestRunner.php similarity index 99% rename from tests/parser/ParserTest.php rename to tests/parser/ParserTestRunner.php index 7b3746abe0..be3f0f7972 100644 --- a/tests/parser/ParserTest.php +++ b/tests/parser/ParserTestRunner.php @@ -1,7 +1,7 @@ @@ -32,7 +32,7 @@ use MediaWiki\MediaWikiServices; /** * @ingroup Testing */ -class ParserTest { +class ParserTestRunner { /** * @var bool $color whereas output should be colorized */ @@ -395,7 +395,7 @@ class ParserTest { public function runTestsFromFiles( $filenames ) { $ok = false; - // be sure, ParserTest::addArticle has correct language set, + // be sure, ParserTestRunner::addArticle has correct language set, // so that system messages gets into the right language cache $GLOBALS['wgLanguageCode'] = 'en'; $GLOBALS['wgContLang'] = Language::factory( 'en' ); @@ -407,7 +407,7 @@ class ParserTest { foreach ( $filenames as $filename ) { echo "Running parser tests from: $filename\n"; - $tests = new TestFileIterator( $filename, $this ); + $tests = new TestFileReader( $filename, $this ); $ok = $this->runTests( $tests ) && $ok; } @@ -838,7 +838,7 @@ class ParserTest { global $wgHooks; $wgHooks['ParserTestParser'][] = 'ParserTestParserHook::setup'; - $wgHooks['ParserGetVariableValueTs'][] = 'ParserTest::getFakeTimestamp'; + $wgHooks['ParserGetVariableValueTs'][] = 'ParserTestRunner::getFakeTimestamp'; MagicWord::clearCache(); MWTidy::destroySingleton(); diff --git a/tests/parser/TestFileDataProvider.php b/tests/parser/TestFileDataProvider.php index 00b1f3f01c..5528605968 100644 --- a/tests/parser/TestFileDataProvider.php +++ b/tests/parser/TestFileDataProvider.php @@ -21,9 +21,9 @@ /** * An iterator for use as a phpunit data provider. Provides the test arguments - * in the order expected by NewParserTest::testParserTest(). + * in the order expected by ParserIntegrationTest::testParserTest(). */ -class TestFileDataProvider extends TestFileIterator { +class TestFileDataProvider extends TestFileReader { function current() { $test = parent::current(); if ( $test ) { diff --git a/tests/parser/TestFileIterator.php b/tests/parser/TestFileReader.php similarity index 93% rename from tests/parser/TestFileIterator.php rename to tests/parser/TestFileReader.php index 731d35c775..18e09ccb7f 100644 --- a/tests/parser/TestFileIterator.php +++ b/tests/parser/TestFileReader.php @@ -19,12 +19,12 @@ * @ingroup Testing */ -class TestFileIterator implements Iterator { +class TestFileReader implements Iterator { private $file; private $fh; /** - * @var ParserTest|MediaWikiParserTest An instance of ParserTest (parserTests.php) - * or MediaWikiParserTest (phpunit) + * @var ParserTestRunner|ParserTestTopLevelSuite An instance of ParserTestRunner + * (parserTests.php) or ParserTestTopLevelSuite (phpunit) */ private $parserTest; private $index = 0; @@ -134,12 +134,12 @@ class TestFileIterator implements Iterator { } $this->test = [ - 'test' => ParserTest::chomp( $this->sectionData['test'] ), + 'test' => ParserTestRunner::chomp( $this->sectionData['test'] ), 'subtest' => $this->nextSubTest, - 'input' => ParserTest::chomp( $this->sectionData[$input] ), - 'result' => ParserTest::chomp( $this->sectionData[$result] ), - 'options' => ParserTest::chomp( $this->sectionData['options'] ), - 'config' => ParserTest::chomp( $this->sectionData['config'] ), + 'input' => ParserTestRunner::chomp( $this->sectionData[$input] ), + 'result' => ParserTestRunner::chomp( $this->sectionData[$result] ), + 'options' => ParserTestRunner::chomp( $this->sectionData['options'] ), + 'config' => ParserTestRunner::chomp( $this->sectionData['config'] ), ]; if ( $tidy != false ) { $this->test['options'] .= " tidy"; @@ -171,7 +171,7 @@ class TestFileIterator implements Iterator { $this->checkSection( 'article' ); $this->parserTest->addArticle( - ParserTest::chomp( $this->sectionData['article'] ), + ParserTestRunner::chomp( $this->sectionData['article'] ), $this->sectionData['text'], $this->lineNum ); $this->clearSection(); diff --git a/tests/parser/fuzzTest.php b/tests/parser/fuzzTest.php index 045a7700cf..ddf839eeec 100644 --- a/tests/parser/fuzzTest.php +++ b/tests/parser/fuzzTest.php @@ -22,13 +22,13 @@ class ParserFuzzTest extends Maintenance { } function finalSetup() { - require_once __DIR__ . '/../TestsAutoLoader.php'; + require_once __DIR__ . '/../common/TestsAutoLoader.php'; } function execute() { $files = $this->getOption( 'file', [ __DIR__ . '/parserTests.txt' ] ); $this->seed = intval( $this->getOption( 'seed', 1 ) ) - 1; - $this->parserTest = new ParserTest; + $this->parserTest = new ParserTestRunner; $this->fuzzTest( $files ); } diff --git a/tests/parserTests.php b/tests/parser/parserTests.php similarity index 95% rename from tests/parserTests.php rename to tests/parser/parserTests.php index 915eac63a7..48c260678e 100644 --- a/tests/parserTests.php +++ b/tests/parser/parserTests.php @@ -30,8 +30,8 @@ $options = [ 'quick', 'color', 'quiet', 'help', 'show-output', 'record', 'run-disabled', 'run-parsoid', 'dwdiff', 'mark-ws' ]; $optionsWithArgs = [ 'regex', 'filter', 'seed', 'setversion', 'file', 'norm' ]; -require_once __DIR__ . '/../maintenance/commandLine.inc'; -require_once __DIR__ . '/TestsAutoLoader.php'; +require_once __DIR__ . '/../../maintenance/commandLine.inc'; +require_once __DIR__ . '/../common/TestsAutoLoader.php'; if ( isset( $options['help'] ) ) { echo <<resetNamespaces(); # reset namespace cache - ParserTest::resetTitleServices(); + ParserTestRunner::resetTitleServices(); MediaWikiServices::getInstance()->disableService( 'MediaHandlerFactory' ); MediaWikiServices::getInstance()->redefineService( 'MediaHandlerFactory', @@ -194,7 +194,7 @@ class NewParserTest extends MediaWikiTestCase { } public static function tearDownAfterClass() { - ParserTest::tearDownInterwikis(); + ParserTestRunner::tearDownInterwikis(); parent::tearDownAfterClass(); } @@ -367,7 +367,7 @@ class NewParserTest extends MediaWikiTestCase { } } - // ParserTest setup/teardown functions + // ParserTestRunner setup/teardown functions /** * Set up the global variables for a consistent environment for each test. @@ -861,7 +861,7 @@ class NewParserTest extends MediaWikiTestCase { foreach ( self::$articles as $name => $info ) { list( $text, $line ) = $info; - ParserTest::addArticle( $name, $text, $line, 'ignoreduplicate' ); + ParserTestRunner::addArticle( $name, $text, $line, 'ignoreduplicate' ); } } diff --git a/tests/phpunit/phpunit.php b/tests/phpunit/phpunit.php index 4158863505..acd8575150 100755 --- a/tests/phpunit/phpunit.php +++ b/tests/phpunit/phpunit.php @@ -79,7 +79,7 @@ class PHPUnitMaintClass extends Maintenance { global $wgAuthManagerConfig, $wgAuth; // Inject test autoloader - require_once __DIR__ . '/../TestsAutoLoader.php'; + require_once __DIR__ . '/../common/TestsAutoLoader.php'; // wfWarn should cause tests to fail $wgDevelopmentWarnings = true; diff --git a/tests/phpunit/suite.xml b/tests/phpunit/suite.xml index ed18205753..6443ec40d6 100644 --- a/tests/phpunit/suite.xml +++ b/tests/phpunit/suite.xml @@ -25,7 +25,7 @@ languages - includes/parser/MediaWikiParserTest.php + suites/ParserTestTopLevelSuite.php suites/ExtensionsParserTestSuite.php diff --git a/tests/phpunit/suites/ExtensionsParserTestSuite.php b/tests/phpunit/suites/ExtensionsParserTestSuite.php index 3d68b24198..8d6ee07956 100644 --- a/tests/phpunit/suites/ExtensionsParserTestSuite.php +++ b/tests/phpunit/suites/ExtensionsParserTestSuite.php @@ -2,7 +2,7 @@ class ExtensionsParserTestSuite extends PHPUnit_Framework_TestSuite { public static function suite() { - return MediaWikiParserTest::suite( MediaWikiParserTest::NO_CORE ); + return ParserTestTopLevelSuite::suite( ParserTestTopLevelSuite::NO_CORE ); } } diff --git a/tests/phpunit/includes/parser/MediaWikiParserTest.php b/tests/phpunit/suites/ParserTestTopLevelSuite.php similarity index 89% rename from tests/phpunit/includes/parser/MediaWikiParserTest.php rename to tests/phpunit/suites/ParserTestTopLevelSuite.php index 173447fcf7..36ecf73a71 100644 --- a/tests/phpunit/includes/parser/MediaWikiParserTest.php +++ b/tests/phpunit/suites/ParserTestTopLevelSuite.php @@ -1,5 +1,5 @@