Allow reset of global services.
[lhc/web/wiklou.git] / tests / parser / parserTest.inc
index 56108c9..0987c0f 100644 (file)
@@ -27,6 +27,7 @@
  * @file
  * @ingroup Testing
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * @ingroup Testing
@@ -244,6 +245,9 @@ class ParserTest {
                // "extra language links"
                // see https://gerrit.wikimedia.org/r/111390
                array_push( $wgExtraInterlanguageLinkPrefixes, 'mul' );
+
+               // Reset all services to be consistent with the new settings!
+               MediaWikiServices::resetGlobalInstance();
        }
 
        /**
@@ -1005,11 +1009,6 @@ class ParserTest {
 
                $this->databaseSetupDone = true;
 
-               # SqlBagOStuff broke when using temporary tables on r40209 (bug 15892).
-               # It seems to have been fixed since (r55079?), but regressed at some point before r85701.
-               # This works around it for now...
-               ObjectCache::$instances[CACHE_DB] = new HashBagOStuff;
-
                # CREATE TEMPORARY TABLE breaks if there is more than one server
                if ( wfGetLB()->getServerCount() != 1 ) {
                        $this->useTemporaryTables = false;
@@ -1036,11 +1035,22 @@ class ParserTest {
                $this->db->insert( 'site_stats',
                        [ 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ] );
 
-               # Reinitialise the LocalisationCache to match the database state
-               Language::getLocalisationCache()->unloadAll();
+               $bootstrapConfig = MediaWikiServices::getInstance()->getBootstrapConfig();
+               $configOverrides = new HashConfig();
 
-               # Clear the message cache
-               MessageCache::singleton()->clear();
+               # SqlBagOStuff broke when using temporary tables on r40209 (bug 15892).
+               # It seems to have been fixed since (r55079?), but regressed at some point before r85701.
+               # This works around it for now...
+               $objectCaches = [
+                               CACHE_DB => [ 'class' => 'HashBagOStuff' ],
+                       ] + $bootstrapConfig->get( 'ObjectCaches' );
+
+               $configOverrides->set( 'ObjectCaches', $objectCaches );
+
+               // Reset all services to be consistent with the new settings!
+               MediaWikiServices::resetGlobalInstance(
+                       new MultiConfig( [ $configOverrides, $bootstrapConfig ] )
+               );
 
                // Remember to update newParserTests.php after changing the below
                // (and it uses a slightly different syntax just for teh lulz)
@@ -1241,11 +1251,7 @@ class ParserTest {
         * after each test runs.
         */
        private function teardownGlobals() {
-               RepoGroup::destroySingleton();
-               FileBackendGroup::destroySingleton();
-               LockManagerGroup::destroySingletons();
-               LinkCache::singleton()->clear();
-               MWTidy::destroySingleton();
+               MediaWikiServices::resetGlobalInstance();
 
                foreach ( $this->savedGlobals as $var => $val ) {
                        $GLOBALS[$var] = $val;