phpunit: Set $wgMainStash to 'hash' during test execution
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 25 Sep 2015 04:51:01 +0000 (05:51 +0100)
committerKrinkle <krinklemail@gmail.com>
Fri, 25 Sep 2015 04:57:31 +0000 (04:57 +0000)
Also clean up the other cache settings to match their order
as defined in DefaultSettings.php.

Don't disable MessageCacheType, ParserCacheType etc. This could
prevent bugs from happening during tests. They are enabled by default
in MediaWiki with CACHE_ANYTHING. At least let them use 'hash'
during tests to resemble a more realistic environment.

Change-Id: Id9edf33c600db3ac4d837e1674a8eb2f5363a4f8

tests/phpunit/MediaWikiTestCase.php
tests/phpunit/phpunit.php

index 73c4066..bd30397 100644 (file)
@@ -103,8 +103,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                 */
                ObjectCache::$instances[CACHE_DB] = new HashBagOStuff;
 
-               // Sandbox APC by replacing with in-process hash cache instead.
-               // Ensures tests are removed between tests.
+               // Sandbox APC by replacing with in-process hash instead.
+               // Ensures values are removed between tests.
                ObjectCache::$instances['apc'] =
                ObjectCache::$instances['xcache'] =
                ObjectCache::$instances['wincache'] = new HashBagOStuff;
index 587d6d0..af924a0 100755 (executable)
@@ -66,11 +66,21 @@ class PHPUnitMaintClass extends Maintenance {
                // wfWarn should cause tests to fail
                $wgDevelopmentWarnings = true;
 
+               // Make sure all caches and stashes are either disabled or use
+               // in-process cache only to prevent tests from using any preconfigured
+               // cache meant for the local wiki from outside the test run.
+               // See also MediaWikiTestCase::run() which mocks CACHE_DB and APC.
+
+               // Disabled in DefaultSettings, override local settings
+               $wgMainWANCache =
                $wgMainCacheType = CACHE_NONE;
-               $wgMainWANCache = CACHE_NONE;
-               $wgMessageCacheType = CACHE_NONE;
-               $wgParserCacheType = CACHE_NONE;
-               $wgLanguageConverterCacheType = CACHE_NONE;
+               // Uses CACHE_ANYTHING in DefaultSettings, use hash instead of db
+               $wgMessageCacheType =
+               $wgParserCacheType =
+               $wgSessionCacheType =
+               $wgLanguageConverterCacheType = 'hash';
+               // Uses db-replicated in DefaultSettings
+               $wgMainStash = 'hash';
 
                $wgUseDatabaseMessages = false; # Set for future resets