4 * Common code for test environment initialisation and teardown
7 public static $bootstrapGlobals;
10 * For use in MediaWikiUnitTestCase.
12 * This should be called before DefaultSettings.php or Setup.php loads.
14 public static function snapshotGlobals() {
15 self
::$bootstrapGlobals = [];
16 foreach ( $GLOBALS as $key => $_ ) {
17 // Support: HHVM (avoid self-ref)
18 if ( $key !== 'GLOBALS' ) {
19 self
::$bootstrapGlobals[ $key ] =& $GLOBALS[$key];
25 * This should be called before Setup.php, e.g. from the finalSetup() method
26 * of a Maintenance subclass
28 public static function applyInitialConfig() {
29 global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgMainWANCache;
31 global $wgObjectCaches;
32 global $wgLanguageConverterCacheType, $wgUseDatabaseMessages;
33 global $wgLocaltimezone, $wgLocalisationCacheConf;
35 global $wgDevelopmentWarnings;
36 global $wgSessionProviders, $wgSessionPbkdf2Iterations;
37 global $wgJobTypeConf;
38 global $wgAuthManagerConfig;
39 global $wgShowExceptionDetails;
41 $wgShowExceptionDetails = true;
43 // wfWarn should cause tests to fail
44 $wgDevelopmentWarnings = true;
46 // Make sure all caches and stashes are either disabled or use
47 // in-process cache only to prevent tests from using any preconfigured
48 // cache meant for the local wiki from outside the test run.
49 // See also MediaWikiTestCase::run() which mocks CACHE_DB and APC.
51 // Disabled in DefaultSettings, override local settings
53 $wgMainCacheType = CACHE_NONE
;
54 // Uses CACHE_ANYTHING in DefaultSettings, use hash instead of db
58 $wgLanguageConverterCacheType = 'hash';
59 // Uses db-replicated in DefaultSettings
60 $wgMainStash = 'hash';
61 // Use hash instead of db
62 $wgObjectCaches['db-replicated'] = $wgObjectCaches['hash'];
63 // Use memory job queue
65 'default' => [ 'class' => JobQueueMemory
::class, 'order' => 'fifo' ],
68 $wgUseDatabaseMessages = false; # Set for future resets
70 // Assume UTC for testing purposes
71 $wgLocaltimezone = 'UTC';
73 $wgLocalisationCacheConf['class'] = TestLocalisationCache
::class;
74 $wgLocalisationCacheConf['storeClass'] = LCStoreNull
::class;
76 // Do not bother updating search tables
77 $wgSearchType = SearchEngineDummy
::class;
79 // Generic MediaWiki\Session\SessionManager configuration for tests
80 // We use CookieSessionProvider because things might be expecting
81 // cookies to show up in a FauxRequest somewhere.
82 $wgSessionProviders = [
84 'class' => MediaWiki\Session\CookieSessionProvider
::class,
87 'callUserSetCookiesHook' => true,
92 // Single-iteration PBKDF2 session secret derivation, for speed.
93 $wgSessionPbkdf2Iterations = 1;
95 // Generic AuthManager configuration for testing
96 $wgAuthManagerConfig = [
100 'class' => MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider
::class,
102 'authoritative' => false,
106 'class' => MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider
::class,
108 'authoritative' => true,
112 'secondaryauth' => [],
115 // T46192 Do not attempt to send a real e-mail
116 Hooks
::clear( 'AlternateUserMailer' );
118 'AlternateUserMailer',
123 // xdebug's default of 100 is too low for MediaWiki
124 ini_set( 'xdebug.max_nesting_level', 1000 );
126 // Bug T116683 serialize_precision of 100
127 // may break testing against floating point values
128 // treated with PHP's serialize()
129 ini_set( 'serialize_precision', 17 );