ParserTestRunner: share more code w/ MediaWikiIntegrationTestCase
Refactor the database setup code to share more code between ParserTestRunner and MediaWikiIntegrationTestCase. Made `::setupAllTestDBs` static so it can be reused from ParserTestRunner. Made ParserTestRunner::addArticle more like MediaWikiIntegrationTestCase::addCoreDBData(). Some additional refactoring work could be done here in the future to share more code. After the refactoring the ParserTestTables hook is no longer necessary and so has been (soft) deprecated. MediaWikiIntegrationTestCase clones all database tables, so ParserTestRunner no longer needs to ask extensions for a list of specific tables it should clone. Cleaning up the handful of extensions which define this hook will be left to a future patch set. Change-Id: I5124789fac333a664b73b4b4a1e801ecc0a618ca
This commit is contained in:
parent
66db49e243
commit
665eae14ac
8 changed files with 99 additions and 149 deletions
|
|
@ -349,6 +349,10 @@ because of Phabricator reports.
|
|||
a bool.
|
||||
* SquidPurgeClient and SquidPurgeClientPool, deprecated since 1.35, have been
|
||||
removed.
|
||||
* ParserTestRunner no longer invokes the ParserTestTables hook, instead
|
||||
cloning all database tables before running tests as MediaWikiIntegrationTest
|
||||
does. If an extension was misusing the hook to *exclude* tables from the
|
||||
clone, that will no longer occur and tests may fail.
|
||||
* …
|
||||
|
||||
=== Deprecations in 1.36 ===
|
||||
|
|
@ -474,6 +478,8 @@ because of Phabricator reports.
|
|||
the direct path to the resources.
|
||||
* The second argument of EnhancedChangesList::getDiffHistLinks, $query, has
|
||||
been deprecated.
|
||||
* The ParserTestTables hook has been deprecated; it is no longer necessary
|
||||
after a ParserTestRunner refactoring.
|
||||
* …
|
||||
|
||||
=== Other changes in 1.36 ===
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ namespace MediaWiki\Hook;
|
|||
*
|
||||
* @stable to implement
|
||||
* @ingroup Hooks
|
||||
* @deprecated No longer invoked by MW 1.36+
|
||||
*/
|
||||
interface ParserTestTablesHook {
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ class MediaWikiServices extends ServiceContainer {
|
|||
* @return MediaWikiServices The old MediaWikiServices object, so it can be restored later.
|
||||
*/
|
||||
public static function forceGlobalInstance( MediaWikiServices $services ) {
|
||||
if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
|
||||
if ( !defined( 'MW_PHPUNIT_TEST' ) && !defined( 'MW_PARSER_TEST' ) ) {
|
||||
throw new MWException( __METHOD__ . ' must not be used outside unit tests.' );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -957,7 +957,7 @@ final class SessionManager implements SessionManagerInterface {
|
|||
* @internal
|
||||
*/
|
||||
public static function resetCache() {
|
||||
if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
|
||||
if ( !defined( 'MW_PHPUNIT_TEST' ) && !defined( 'MW_PARSER_TEST' ) ) {
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new MWException( __METHOD__ . ' may only be called from unit tests!' );
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ use Wikimedia\Parsoid\ParserTests\StyleTag as ParsoidStyleTag;
|
|||
use Wikimedia\Parsoid\ParserTests\Test as ParsoidTest;
|
||||
use Wikimedia\Parsoid\ParserTests\TestUtils as ParsoidTestUtils;
|
||||
use Wikimedia\Parsoid\Parsoid;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
use Wikimedia\ScopedCallback;
|
||||
use Wikimedia\TestingAccessWrapper;
|
||||
|
||||
|
|
@ -60,11 +59,6 @@ class ParserTestRunner {
|
|||
'extraParserTests.txt',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var bool Use temporary tables for the temporary database
|
||||
*/
|
||||
private $useTemporaryTables = true;
|
||||
|
||||
/**
|
||||
* @var array The status of each setup function
|
||||
*/
|
||||
|
|
@ -72,7 +66,6 @@ class ParserTestRunner {
|
|||
'staticSetup' => false,
|
||||
'perTestSetup' => false,
|
||||
'setupDatabase' => false,
|
||||
'setDatabase' => false,
|
||||
'setupUploads' => false,
|
||||
];
|
||||
|
||||
|
|
@ -140,6 +133,11 @@ class ParserTestRunner {
|
|||
/** @var Title */
|
||||
private $defaultTitle;
|
||||
|
||||
/**
|
||||
* Table name prefix.
|
||||
*/
|
||||
public const DB_PREFIX = 'parsertest_';
|
||||
|
||||
/**
|
||||
* @param TestRecorder $recorder
|
||||
* @param array $options
|
||||
|
|
@ -551,14 +549,10 @@ class ParserTestRunner {
|
|||
/**
|
||||
* Ensure one of the given setup stages has been done, throw an exception otherwise.
|
||||
* @param string $funcName
|
||||
* @param string|null $funcName2
|
||||
*/
|
||||
protected function checkSetupDone( string $funcName, string $funcName2 = null ) {
|
||||
if ( !$this->setupDone[$funcName]
|
||||
&& ( $funcName2 === null || !$this->setupDone[$funcName2] )
|
||||
) {
|
||||
$name = ( $funcName2 === null ) ? $funcName : "$funcName or $funcName2";
|
||||
throw new MWException( "$name must be called before calling " . wfGetCaller() );
|
||||
protected function checkSetupDone( string $funcName ) {
|
||||
if ( !$this->setupDone[$funcName] ) {
|
||||
throw new MWException( "$funcName must be called before calling " . wfGetCaller() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -731,8 +725,9 @@ class ParserTestRunner {
|
|||
public function runTestsFromFiles( $filenames ) {
|
||||
$ok = false;
|
||||
|
||||
$teardownGuard = $this->staticSetup();
|
||||
$teardownGuard = null;
|
||||
$teardownGuard = $this->setupDatabase( $teardownGuard );
|
||||
$teardownGuard = $this->staticSetup( $teardownGuard );
|
||||
$teardownGuard = $this->setupUploads( $teardownGuard );
|
||||
|
||||
$this->recorder->start();
|
||||
|
|
@ -1192,7 +1187,7 @@ class ParserTestRunner {
|
|||
public function perTestSetup( $test, $nextTeardown = null ) {
|
||||
$teardown = [];
|
||||
|
||||
$this->checkSetupDone( 'setupDatabase', 'setDatabase' );
|
||||
$this->checkSetupDone( 'setupDatabase' );
|
||||
$teardown[] = $this->markSetupDone( 'perTestSetup' );
|
||||
|
||||
$opts = is_array( $test ) ? $test['options'] : $test->options;
|
||||
|
|
@ -1322,52 +1317,15 @@ class ParserTestRunner {
|
|||
return $this->createTeardownObject( $teardown, $nextTeardown );
|
||||
}
|
||||
|
||||
/**
|
||||
* List of temporary tables to create, without prefix.
|
||||
* Some of these probably aren't necessary.
|
||||
* @return string[]
|
||||
*/
|
||||
private function listTables() {
|
||||
$tables = [ 'user', 'user_properties', 'user_former_groups', 'page', 'page_restrictions',
|
||||
'protected_titles', 'revision', 'ip_changes', 'text', 'pagelinks', 'imagelinks',
|
||||
'categorylinks', 'templatelinks', 'externallinks', 'langlinks', 'iwlinks',
|
||||
'site_stats', 'ipblocks', 'image', 'oldimage',
|
||||
'recentchanges', 'watchlist', 'interwiki', 'logging', 'log_search',
|
||||
'querycache', 'objectcache', 'job', 'l10n_cache', 'redirect', 'querycachetwo',
|
||||
'archive', 'user_groups', 'page_props', 'category',
|
||||
'slots', 'content', 'slot_roles', 'content_models',
|
||||
'comment', 'revision_comment_temp', 'actor', 'revision_actor_temp',
|
||||
'change_tag', 'change_tag_def',
|
||||
];
|
||||
|
||||
if ( in_array( $this->db->getType(), [ 'mysql', 'sqlite' ] ) ) {
|
||||
array_push( $tables, 'searchindex' );
|
||||
}
|
||||
|
||||
// Allow extensions to add to the list of tables to duplicate;
|
||||
// may be necessary if they hook into page save or other code
|
||||
// which will require them while running tests.
|
||||
Hooks::runner()->onParserTestTables( $tables );
|
||||
|
||||
return $tables;
|
||||
}
|
||||
|
||||
public function setDatabase( IDatabase $db ) {
|
||||
$this->db = $db;
|
||||
$this->setupDone['setDatabase'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up temporary DB tables.
|
||||
*
|
||||
* For best performance, call this once only for all tests. However, it can
|
||||
* be called at the start of each test if more isolation is desired.
|
||||
*
|
||||
* @todo This is basically an unrefactored copy of
|
||||
* MediaWikiIntegrationTestCase::setupAllTestDBs. They should be factored out somehow.
|
||||
*
|
||||
* Do not call this function from a MediaWikiIntegrationTestCase subclass, since
|
||||
* MediaWikiIntegrationTestCase does its own DB setup. Instead use setDatabase().
|
||||
* Do not call this function from a MediaWikiIntegrationTestCase subclass,
|
||||
* since MediaWikiIntegrationTestCase does its own DB setup.
|
||||
*
|
||||
* @see staticSetup() for more information about setup/teardown
|
||||
*
|
||||
|
|
@ -1377,33 +1335,31 @@ class ParserTestRunner {
|
|||
public function setupDatabase( $nextTeardown = null ) {
|
||||
global $wgDBprefix;
|
||||
|
||||
$this->db = MediaWikiServices::getInstance()->getDBLoadBalancer()->getConnection( DB_MASTER );
|
||||
$dbType = $this->db->getType();
|
||||
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
||||
$this->db = $lb->getConnection( DB_MASTER );
|
||||
|
||||
$suspiciousPrefixes = [ 'parsertest_', MediaWikiIntegrationTestCase::DB_PREFIX ];
|
||||
$suspiciousPrefixes = [ self::DB_PREFIX, MediaWikiIntegrationTestCase::DB_PREFIX ];
|
||||
if ( in_array( $wgDBprefix, $suspiciousPrefixes ) ) {
|
||||
throw new MWException( "\$wgDBprefix=$wgDBprefix suggests DB setup is already done" );
|
||||
}
|
||||
|
||||
$teardown = [];
|
||||
|
||||
$teardown[] = $this->markSetupDone( 'setupDatabase' );
|
||||
|
||||
# CREATE TEMPORARY TABLE breaks if there is more than one server
|
||||
if ( MediaWikiServices::getInstance()->getDBLoadBalancer()->getServerCount() != 1 ) {
|
||||
$this->useTemporaryTables = false;
|
||||
}
|
||||
|
||||
$temporary = $this->useTemporaryTables || $dbType == 'postgres';
|
||||
$prefix = 'parsertest_';
|
||||
|
||||
$this->dbClone = new CloneDatabase( $this->db, $this->listTables(), $prefix );
|
||||
$this->dbClone->useTemporaryTables( $temporary );
|
||||
$this->dbClone->cloneTableStructure();
|
||||
CloneDatabase::changePrefix( $prefix );
|
||||
|
||||
// Set up a test DB just for parser tests
|
||||
MediaWikiIntegrationTestCase::setupAllTestDBs(
|
||||
$this->db,
|
||||
self::DB_PREFIX,
|
||||
true // postgres requires that we use temporary tables
|
||||
);
|
||||
MediaWikiIntegrationTestCase::resetNonServiceCaches();
|
||||
$teardown[] = function () {
|
||||
$this->teardownDatabase();
|
||||
MediaWikiIntegrationTestCase::teardownTestDB();
|
||||
};
|
||||
|
||||
MediaWikiIntegrationTestCase::installMockMwServices();
|
||||
$teardown[] = function () {
|
||||
MediaWikiIntegrationTestCase::restoreMwServices();
|
||||
};
|
||||
|
||||
// Wipe some DB query result caches on setup and teardown
|
||||
|
|
@ -1421,8 +1377,7 @@ class ParserTestRunner {
|
|||
|
||||
/**
|
||||
* Add data about uploads to the new test DB, and set up the upload
|
||||
* directory. This should be called after either setDatabase() or
|
||||
* setupDatabase().
|
||||
* directory. This should be called after setupDatabase().
|
||||
*
|
||||
* @param ScopedCallback|null $nextTeardown The next teardown object
|
||||
* @return ScopedCallback The teardown object
|
||||
|
|
@ -1430,7 +1385,7 @@ class ParserTestRunner {
|
|||
public function setupUploads( $nextTeardown = null ) {
|
||||
$teardown = [];
|
||||
|
||||
$this->checkSetupDone( 'setupDatabase', 'setDatabase' );
|
||||
$this->checkSetupDone( 'setupDatabase' );
|
||||
$teardown[] = $this->markSetupDone( 'setupUploads' );
|
||||
|
||||
// Create the files in the upload directory (or pretend to create them
|
||||
|
|
@ -1627,36 +1582,6 @@ class ParserTestRunner {
|
|||
return $this->createTeardownObject( $teardown, $nextTeardown );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for database teardown, called from the teardown closure. Destroy
|
||||
* the database clone and fix up some things that CloneDatabase doesn't fix.
|
||||
*
|
||||
* @todo Move most things here to CloneDatabase
|
||||
*/
|
||||
private function teardownDatabase() {
|
||||
$this->checkSetupDone( 'setupDatabase' );
|
||||
|
||||
$this->dbClone->destroy();
|
||||
|
||||
if ( $this->useTemporaryTables ) {
|
||||
if ( $this->db->getType() == 'sqlite' ) {
|
||||
# Under SQLite the searchindex table is virtual and need
|
||||
# to be explicitly destroyed. See T31912
|
||||
# See also MediaWikiIntegrationTestCase::destroyDB()
|
||||
wfDebug( __METHOD__ . " explicitly destroying sqlite virtual table parsertest_searchindex" );
|
||||
$this->db->query( "DROP TABLE `parsertest_searchindex`" );
|
||||
}
|
||||
# Don't need to do anything
|
||||
return;
|
||||
}
|
||||
|
||||
$tables = $this->listTables();
|
||||
|
||||
foreach ( $tables as $table ) {
|
||||
$this->db->query( "DROP TABLE `parsertest_$table`" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload test files to the backend created by createRepoGroup().
|
||||
*
|
||||
|
|
@ -1767,7 +1692,7 @@ class ParserTestRunner {
|
|||
public function addArticles(
|
||||
array $articles, ?ScopedCallback $nextTeardown = null
|
||||
): ScopedCallback {
|
||||
$this->checkSetupDone( 'setupDatabase', 'setDatabase' );
|
||||
$this->checkSetupDone( 'setupDatabase' );
|
||||
$this->checkSetupDone( 'staticSetup' );
|
||||
|
||||
$setup = [];
|
||||
|
|
@ -1822,9 +1747,9 @@ class ParserTestRunner {
|
|||
* @param array $articles Article info array from TestFileReader
|
||||
*/
|
||||
public function cleanupArticles( $articles ) {
|
||||
$this->checkSetupDone( 'setupDatabase', 'setDatabase' );
|
||||
$this->checkSetupDone( 'setupDatabase' );
|
||||
$this->checkSetupDone( 'staticSetup' );
|
||||
$user = RequestContext::getMain()->getUser();
|
||||
$user = MediaWikiIntegrationTestCase::getTestSysop()->getUser();
|
||||
foreach ( $articles as $info ) {
|
||||
$name = self::chomp( $info['name'] );
|
||||
$title = Title::newFromText( $name );
|
||||
|
|
@ -1835,6 +1760,10 @@ class ParserTestRunner {
|
|||
|
||||
/**
|
||||
* Insert a temporary test article
|
||||
*
|
||||
* @see MediaWikiIntegrationTestCase::addCoreDBData()
|
||||
* @todo Refactor to share more code w/ ::addCoreDBData() or ::editPage
|
||||
*
|
||||
* @param string $name The title, including any prefix
|
||||
* @param string $text The article text
|
||||
* @param string $file The input file name
|
||||
|
|
@ -1853,6 +1782,8 @@ class ParserTestRunner {
|
|||
throw new MWException( "invalid title '$name' at $file:$line\n" );
|
||||
}
|
||||
|
||||
$user = MediaWikiIntegrationTestCase::getTestSysop()->getUser();
|
||||
|
||||
$newContent = ContentHandler::makeContent( $text, $title );
|
||||
|
||||
$page = WikiPage::factory( $title );
|
||||
|
|
@ -1883,7 +1814,9 @@ class ParserTestRunner {
|
|||
$status = $page->doEditContent(
|
||||
$newContent,
|
||||
'',
|
||||
EDIT_NEW | EDIT_INTERNAL
|
||||
EDIT_NEW | EDIT_SUPPRESS_RC | EDIT_INTERNAL,
|
||||
false,
|
||||
$user
|
||||
);
|
||||
} finally {
|
||||
if ( $restore ) {
|
||||
|
|
@ -1895,6 +1828,12 @@ class ParserTestRunner {
|
|||
throw new MWException( $status->getWikiText( false, false, 'en' ) );
|
||||
}
|
||||
|
||||
// an edit always attempt to purge backlink links such as history
|
||||
// pages. That is unnecessary.
|
||||
JobQueueGroup::singleton()->get( 'htmlCacheUpdate' )->delete();
|
||||
// WikiPages::doEditUpdates randomly adds RC purges
|
||||
JobQueueGroup::singleton()->get( 'recentChangesUpdate' )->delete();
|
||||
|
||||
// The RepoGroup cache is invalidated by the creation of file redirects
|
||||
if ( $title->inNamespace( NS_FILE ) ) {
|
||||
MediaWikiServices::getInstance()->getRepoGroup()->clearCache( $title );
|
||||
|
|
|
|||
|
|
@ -66,6 +66,13 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
|
|||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Cloned database
|
||||
*
|
||||
* @var ?CloneDatabase
|
||||
*/
|
||||
private static $dbClone = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @since 1.19
|
||||
|
|
@ -408,7 +415,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
|
|||
if ( !self::$dbSetup || $this->needsDB() ) {
|
||||
// set up a DB connection for this test to use
|
||||
|
||||
self::$useTemporaryTables = !$this->getCliArg( 'use-normal-tables' );
|
||||
$useTemporaryTables = !$this->getCliArg( 'use-normal-tables' );
|
||||
self::$reuseDB = $this->getCliArg( 'reuse-db' );
|
||||
|
||||
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
||||
|
|
@ -417,7 +424,9 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
|
|||
$this->checkDbIsSupported();
|
||||
|
||||
if ( !self::$dbSetup ) {
|
||||
$this->setupAllTestDBs();
|
||||
self::setupAllTestDBs(
|
||||
$this->db, $this->dbPrefix(), $useTemporaryTables
|
||||
);
|
||||
$this->addCoreDBData();
|
||||
}
|
||||
|
||||
|
|
@ -1450,6 +1459,11 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
|
|||
JobQueueGroup::singleton()->get( $type )->delete();
|
||||
}
|
||||
|
||||
if ( self::$dbClone ) {
|
||||
self::$dbClone->destroy( true );
|
||||
self::$dbClone = null;
|
||||
}
|
||||
|
||||
// T219673: close any connections from code that failed to call reuseConnection()
|
||||
// or is still holding onto a DBConnRef instance (e.g. in a singleton).
|
||||
MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->closeAll();
|
||||
|
|
@ -1492,9 +1506,9 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
|
|||
|
||||
$db->tablePrefix( $oldPrefix );
|
||||
$tablesCloned = self::listTables( $db );
|
||||
$dbClone = new CloneDatabase( $db, $tablesCloned, $prefix, $oldPrefix );
|
||||
$dbClone->useTemporaryTables( self::$useTemporaryTables );
|
||||
$dbClone->cloneTableStructure();
|
||||
self::$dbClone = new CloneDatabase( $db, $tablesCloned, $prefix, $oldPrefix );
|
||||
self::$dbClone->useTemporaryTables( self::$useTemporaryTables );
|
||||
self::$dbClone->cloneTableStructure();
|
||||
|
||||
$db->tablePrefix( $prefix );
|
||||
$db->_originalTablePrefix = $oldPrefix;
|
||||
|
|
@ -1506,15 +1520,16 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function setupAllTestDBs() {
|
||||
public static function setupAllTestDBs( $db, ?string $testPrefix = null, ?bool $useTemporaryTables = null ) {
|
||||
global $wgDBprefix;
|
||||
|
||||
self::$oldTablePrefix = $wgDBprefix;
|
||||
|
||||
$testPrefix = $this->dbPrefix();
|
||||
$testPrefix = $testPrefix ?? self::getTestPrefixFor( $db );
|
||||
|
||||
// switch to a temporary clone of the database
|
||||
self::setupTestDB( $this->db, $testPrefix );
|
||||
self::$useTemporaryTables = $useTemporaryTables ?? self::$useTemporaryTables;
|
||||
self::setupTestDB( $db, $testPrefix );
|
||||
|
||||
if ( self::isUsingExternalStoreDB() ) {
|
||||
self::setupExternalStoreTestDBs( $testPrefix );
|
||||
|
|
@ -1844,12 +1859,12 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
|
|||
$originalTables = $this->listOriginalTables( $db );
|
||||
$tables = array_intersect( $tables, $originalTables );
|
||||
|
||||
$dbClone = new CloneDatabase( $db, $tables, $db->tablePrefix(), $db->_originalTablePrefix );
|
||||
$dbClone->useTemporaryTables( self::$useTemporaryTables );
|
||||
$dbClone->cloneTableStructure();
|
||||
self::$dbClone = new CloneDatabase( $db, $tables, $db->tablePrefix(), $db->_originalTablePrefix );
|
||||
self::$dbClone->useTemporaryTables( self::$useTemporaryTables );
|
||||
self::$dbClone->cloneTableStructure();
|
||||
|
||||
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
||||
$lb->setTempTablesOnlyMode( self::$useTemporaryTables, $lb->getLocalDomainID() );
|
||||
$lb->setTempTablesOnlyMode( self::$useTemporaryTables, $db->getDomainID() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1927,7 +1942,8 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
|
|||
}
|
||||
|
||||
private static function isNotUnittest( $table ) {
|
||||
return strpos( $table, self::DB_PREFIX ) !== 0;
|
||||
return strpos( $table, self::DB_PREFIX ) !== 0 &&
|
||||
strpos( $table, ParserTestRunner::DB_PREFIX ) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -24,7 +24,10 @@ class TestUser {
|
|||
|
||||
private function assertNotReal() {
|
||||
global $wgDBprefix;
|
||||
if ( $wgDBprefix !== MediaWikiIntegrationTestCase::DB_PREFIX ) {
|
||||
if (
|
||||
$wgDBprefix !== MediaWikiIntegrationTestCase::DB_PREFIX &&
|
||||
$wgDBprefix !== ParserTestRunner::DB_PREFIX
|
||||
) {
|
||||
throw new MWException( "Can't create user on real database" );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use PHPUnit\Framework\TestSuite;
|
||||
use Wikimedia\ScopedCallback;
|
||||
|
||||
|
|
@ -22,8 +21,6 @@ class ParserTestTopLevelSuite extends TestSuite {
|
|||
/** @var ScopedCallback */
|
||||
private $ptTeardownScope;
|
||||
|
||||
private $oldTablePrefix = '';
|
||||
|
||||
/**
|
||||
* @defgroup filtering_constants Filtering constants
|
||||
*
|
||||
|
|
@ -150,36 +147,24 @@ class ParserTestTopLevelSuite extends TestSuite {
|
|||
}
|
||||
|
||||
protected function setUp() : void {
|
||||
wfDebug( __METHOD__ );
|
||||
|
||||
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
||||
$db = $lb->getConnection( DB_MASTER );
|
||||
$type = $db->getType();
|
||||
$prefix = MediaWikiIntegrationTestCase::DB_PREFIX;
|
||||
$this->oldTablePrefix = $db->tablePrefix();
|
||||
MediaWikiIntegrationTestCase::setupTestDB( $db, $prefix );
|
||||
CloneDatabase::changePrefix( $prefix );
|
||||
|
||||
$this->ptRunner->setDatabase( $db );
|
||||
|
||||
MediaWikiIntegrationTestCase::resetNonServiceCaches();
|
||||
|
||||
MediaWikiIntegrationTestCase::installMockMwServices();
|
||||
$teardown = new ScopedCallback( function () {
|
||||
MediaWikiIntegrationTestCase::restoreMwServices();
|
||||
} );
|
||||
// MediaWikiIntegrationTestCase leaves its test DB hanging around.
|
||||
// we want to make sure we have a clean instance, so tear down any
|
||||
// existing test DB. This has no effect if no test DB exists.
|
||||
MediaWikiIntegrationTestCase::teardownTestDB();
|
||||
// Similarly, make sure we don't reuse Test users from other tests
|
||||
TestUserRegistry::clear();
|
||||
|
||||
$teardown = $this->ptRunner->setupDatabase( null );
|
||||
$teardown = $this->ptRunner->staticSetup( $teardown );
|
||||
$teardown = $this->ptRunner->setupUploads( $teardown );
|
||||
$this->ptTeardownScope = $teardown;
|
||||
}
|
||||
|
||||
protected function tearDown() : void {
|
||||
wfDebug( __METHOD__ );
|
||||
if ( $this->ptTeardownScope ) {
|
||||
ScopedCallback::consume( $this->ptTeardownScope );
|
||||
}
|
||||
CloneDatabase::changePrefix( $this->oldTablePrefix );
|
||||
TestUserRegistry::clear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue