3use Wikimedia\ScopedCallback;
62 public static function suite( $flags = self::CORE_ONLY ) {
63 return new self( $flags );
67 parent::__construct();
72 if ( is_string( $flags ) ) {
77 $mwTestDir =
$IP .
'/tests/';
79 # Human friendly helpers
83 # Will hold the .txt parser test files we will include
86 # Filter out .txt files
88 foreach ( $files as $extName => $parserTestFile ) {
89 $isCore = ( 0 === strpos( $parserTestFile, $mwTestDir ) );
91 if ( $isCore && $wantsCore ) {
92 self::debug(
"included core parser tests: $parserTestFile" );
93 $filesToTest[$extName] = $parserTestFile;
94 } elseif ( !$isCore && $wantsRest ) {
95 self::debug(
"included non core parser tests: $parserTestFile" );
96 $filesToTest[$extName] = $parserTestFile;
98 self::debug(
"skipped parser tests: $parserTestFile" );
102 . implode(
' ', $filesToTest ) );
106 foreach ( $filesToTest as $extensionName => $fileName ) {
107 if ( is_int( $extensionName ) ) {
111 $extensionName = basename( dirname( $fileName ) );
113 $testsName = $extensionName .
'__' . basename( $fileName,
'.txt' );
114 $parserTestClassName = ucfirst( $testsName );
118 $parserTestClassName =
'ParserTest_' .
119 preg_replace(
'/[^a-zA-Z0-9_\x7f-\xff]/',
'_', $parserTestClassName );
121 if ( isset( $testList[$parserTestClassName] ) ) {
124 $parserTestClassName .= $counter;
126 $testList[$parserTestClassName] =
true;
131 self::debug(
"Adding test class $parserTestClassName" );
133 $this->ptRunner, $parserTestClassName, $fileName ) );
141 $type = $db->getType();
142 $prefix =
$type ===
'oracle' ?
143 MediaWikiTestCase::ORA_DB_PREFIX : MediaWikiTestCase::DB_PREFIX;
144 $this->oldTablePrefix = $db->tablePrefix();
145 MediaWikiTestCase::setupTestDB( $db, $prefix );
148 $this->ptRunner->setDatabase( $db );
150 MediaWikiTestCase::resetNonServiceCaches();
152 MediaWikiTestCase::installMockMwServices();
153 $teardown =
new ScopedCallback(
function () {
154 MediaWikiTestCase::restoreMwServices();
157 $teardown = $this->ptRunner->setupUploads( $teardown );
158 $this->ptTeardownScope = $teardown;
163 if ( $this->ptTeardownScope ) {
164 ScopedCallback::consume( $this->ptTeardownScope );
173 protected static function debug( $msg ) {
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfGetCaller( $level=2)
Get the name of the function which called this function wfGetCaller( 1 ) is the function with the wfG...
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
static changePrefix( $prefix)
Change the table prefix on all open DB connections/.
This is the suite class for running tests within a single .txt source file.
static getParserTestFiles()
Get list of filenames to extension and core parser tests.
The UnitTest must be either a class that inherits from MediaWikiTestCase or a class that provides a p...
ScopedCallback $ptTeardownScope
static debug( $msg)
Write $msg under log group 'tests-parser'.
static suite( $flags=self::CORE_ONLY)
Get a PHPUnit test suite of parser tests.
ParserTestRunner $ptRunner
const NO_CORE
Include non core files as set in $wgParserTestFiles.
const WITH_ALL
Include anything set via $wgParserTestFiles.
const CORE_ONLY
Include files shipped with MediaWiki core.