ptRecorder = new PhpunitTestRecorder; $this->ptRunner = new ParserTestRunner( $this->ptRecorder ); if ( is_string( $flags ) ) { $flags = self::CORE_ONLY; } global $wgParserTestFiles, $IP; $mwTestDir = $IP . '/tests/'; # Human friendly helpers $wantsCore = ( $flags & self::CORE_ONLY ); $wantsRest = ( $flags & self::NO_CORE ); # Will hold the .txt parser test files we will include $filesToTest = []; # Filter out .txt files foreach ( $wgParserTestFiles as $parserTestFile ) { $isCore = ( 0 === strpos( $parserTestFile, $mwTestDir ) ); if ( $isCore && $wantsCore ) { self::debug( "included core parser tests: $parserTestFile" ); $filesToTest[] = $parserTestFile; } elseif ( !$isCore && $wantsRest ) { self::debug( "included non core parser tests: $parserTestFile" ); $filesToTest[] = $parserTestFile; } else { self::debug( "skipped parser tests: $parserTestFile" ); } } self::debug( 'parser tests files: ' . implode( ' ', $filesToTest ) ); $testList = []; $counter = 0; foreach ( $filesToTest as $fileName ) { // Call the highest level directory the extension name. // It may or may not actually be, but it should be close // enough to cause there to be separate names for different // things, which is good enough for our purposes. $extensionName = basename( dirname( $fileName ) ); $testsName = $extensionName . '__' . basename( $fileName, '.txt' ); $parserTestClassName = ucfirst( $testsName ); // Official spec for class names: http://php.net/manual/en/language.oop5.basic.php // Prepend 'ParserTest_' to be paranoid about it not starting with a number $parserTestClassName = 'ParserTest_' . preg_replace( '/[^a-zA-Z0-9_\x7f-\xff]/', '_', $parserTestClassName ); if ( isset( $testList[$parserTestClassName] ) ) { // If there is a conflict, append a number. $counter++; $parserTestClassName .= $counter; } $testList[$parserTestClassName] = true; // Previously we actually created a class here, with eval(). We now // just override the name. self::debug( "Adding test class $parserTestClassName" ); $this->addTest( new ParserTestFileSuite( $this->ptRunner, $parserTestClassName, $fileName ) ); } } public function setUp() { wfDebug( __METHOD__ ); $db = wfGetDB( DB_MASTER ); $type = $db->getType(); $prefix = $type === 'oracle' ? MediaWikiTestCase::ORA_DB_PREFIX : MediaWikiTestCase::DB_PREFIX; MediaWikiTestCase::setupTestDB( $db, $prefix ); $teardown = $this->ptRunner->setDatabase( $db ); $teardown = $this->ptRunner->setupUploads( $teardown ); $this->ptTeardownScope = $teardown; } public function tearDown() { wfDebug( __METHOD__ ); if ( $this->ptTeardownScope ) { ScopedCallback::consume( $this->ptTeardownScope ); } } /** * Write $msg under log group 'tests-parser' * @param string $msg Message to log */ protected static function debug( $msg ) { return wfDebugLog( 'tests-parser', wfGetCaller() . ' ' . $msg ); } }