Fix global objects and singletons in NewParserTest
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Sat, 4 May 2013 12:21:39 +0000 (14:21 +0200)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 10 May 2013 20:47:35 +0000 (20:47 +0000)
- Don't set $wgMemc, $parserMemc and $messageMemc on each test,
  the correct values for $wgMainCacheType and such are already set
  in phpunit.php, so those objects are already the good ones
- Only destroy RepoGroup and FileBackendGroup once before starting
  the tests instead of two
- No need to clear the MessageCache in addDBData(), it is already
  destroyed in setupGlobals() (also avoids creating an object on
  some tests to only call clear() on it)
- Group singleton cleanup after the test in tearDown()

Change-Id: Ib2d6522019160f63f3f968e69940413a1def2f8b

tests/phpunit/includes/parser/NewParserTest.php

index f41c71c..7ec364d 100644 (file)
@@ -100,9 +100,6 @@ class NewParserTest extends MediaWikiTestCase {
                                'createtalk' => true,
                ) );
                $tmpGlobals['wgNamespaceProtection'] = array( NS_MEDIAWIKI => 'editinterface' );
-               $tmpGlobals['wgMemc'] = new EmptyBagOStuff;
-               $tmpGlobals['messageMemc'] = wfGetMessageCacheStorage();
-               $tmpGlobals['parserMemc'] = wfGetParserCacheStorage();
 
                $tmpGlobals['wgParser'] = new StubObject( 'wgParser', $GLOBALS['wgParserConf']['class'], array( $GLOBALS['wgParserConf'] ) );
 
@@ -142,6 +139,12 @@ class NewParserTest extends MediaWikiTestCase {
                RepoGroup::destroySingleton();
                FileBackendGroup::destroySingleton();
 
+               // Remove temporary pages from the link cache
+               LinkCache::singleton()->clear();
+
+               // Restore message cache (temporary pages and $wgUseDatabaseMessages)
+               MessageCache::destroyInstance();
+
                parent::tearDown();
        }
 
@@ -197,9 +200,6 @@ class NewParserTest extends MediaWikiTestCase {
                        __METHOD__
                );
 
-               # Clear the message cache
-               MessageCache::singleton()->clear();
-
                $user = User::newFromId( 0 );
                LinkCache::singleton()->clear(); # Avoids the odd failure at creating the nullRevision
 
@@ -376,6 +376,8 @@ class NewParserTest extends MediaWikiTestCase {
                }
 
                MagicWord::clearCache();
+
+               # The entries saved into RepoGroup cache with previous globals will be wrong.
                RepoGroup::destroySingleton();
                FileBackendGroup::destroySingleton();
 
@@ -385,9 +387,6 @@ class NewParserTest extends MediaWikiTestCase {
                # Publish the articles after we have the final language set
                $this->publishTestArticles();
 
-               # The entries saved into RepoGroup cache with previous globals will be wrong.
-               RepoGroup::destroySingleton();
-               FileBackendGroup::destroySingleton();
                MessageCache::destroyInstance();
 
                return $context;
@@ -454,9 +453,6 @@ class NewParserTest extends MediaWikiTestCase {
                foreach ( $this->savedGlobals as $var => $val ) {
                        $GLOBALS[$var] = $val;
                }
-
-               RepoGroup::destroySingleton();
-               LinkCache::singleton()->clear();
        }
 
        /**