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['storeClass'] = LCStoreNull
::class;
75 // Do not bother updating search tables
76 $wgSearchType = SearchEngineDummy
::class;
78 // Generic MediaWiki\Session\SessionManager configuration for tests
79 // We use CookieSessionProvider because things might be expecting
80 // cookies to show up in a FauxRequest somewhere.
81 $wgSessionProviders = [
83 'class' => MediaWiki\Session\CookieSessionProvider
::class,
86 'callUserSetCookiesHook' => true,
91 // Single-iteration PBKDF2 session secret derivation, for speed.
92 $wgSessionPbkdf2Iterations = 1;
94 // Generic AuthManager configuration for testing
95 $wgAuthManagerConfig = [
99 'class' => MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider
::class,
101 'authoritative' => false,
105 'class' => MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider
::class,
107 'authoritative' => true,
111 'secondaryauth' => [],
114 // T46192 Do not attempt to send a real e-mail
115 Hooks
::clear( 'AlternateUserMailer' );
117 'AlternateUserMailer',
122 // xdebug's default of 100 is too low for MediaWiki
123 ini_set( 'xdebug.max_nesting_level', 1000 );
125 // Bug T116683 serialize_precision of 100
126 // may break testing against floating point values
127 // treated with PHP's serialize()
128 ini_set( 'serialize_precision', 17 );