Make LocalisationCache a service
[lhc/web/wiklou.git] / tests / common / TestSetup.php
1 <?php
2
3 /**
4 * Common code for test environment initialisation and teardown
5 */
6 class TestSetup {
7 public static $bootstrapGlobals;
8
9 /**
10 * For use in MediaWikiUnitTestCase.
11 *
12 * This should be called before DefaultSettings.php or Setup.php loads.
13 */
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];
20 }
21 }
22 }
23
24 /**
25 * This should be called before Setup.php, e.g. from the finalSetup() method
26 * of a Maintenance subclass
27 */
28 public static function applyInitialConfig() {
29 global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgMainWANCache;
30 global $wgMainStash;
31 global $wgObjectCaches;
32 global $wgLanguageConverterCacheType, $wgUseDatabaseMessages;
33 global $wgLocaltimezone, $wgLocalisationCacheConf;
34 global $wgSearchType;
35 global $wgDevelopmentWarnings;
36 global $wgSessionProviders, $wgSessionPbkdf2Iterations;
37 global $wgJobTypeConf;
38 global $wgAuthManagerConfig;
39 global $wgShowExceptionDetails;
40
41 $wgShowExceptionDetails = true;
42
43 // wfWarn should cause tests to fail
44 $wgDevelopmentWarnings = true;
45
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.
50
51 // Disabled in DefaultSettings, override local settings
52 $wgMainWANCache =
53 $wgMainCacheType = CACHE_NONE;
54 // Uses CACHE_ANYTHING in DefaultSettings, use hash instead of db
55 $wgMessageCacheType =
56 $wgParserCacheType =
57 $wgSessionCacheType =
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
64 $wgJobTypeConf = [
65 'default' => [ 'class' => JobQueueMemory::class, 'order' => 'fifo' ],
66 ];
67
68 $wgUseDatabaseMessages = false; # Set for future resets
69
70 // Assume UTC for testing purposes
71 $wgLocaltimezone = 'UTC';
72
73 $wgLocalisationCacheConf['class'] = TestLocalisationCache::class;
74 $wgLocalisationCacheConf['storeClass'] = LCStoreNull::class;
75
76 // Do not bother updating search tables
77 $wgSearchType = SearchEngineDummy::class;
78
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 = [
83 [
84 'class' => MediaWiki\Session\CookieSessionProvider::class,
85 'args' => [ [
86 'priority' => 30,
87 'callUserSetCookiesHook' => true,
88 ] ],
89 ],
90 ];
91
92 // Single-iteration PBKDF2 session secret derivation, for speed.
93 $wgSessionPbkdf2Iterations = 1;
94
95 // Generic AuthManager configuration for testing
96 $wgAuthManagerConfig = [
97 'preauth' => [],
98 'primaryauth' => [
99 [
100 'class' => MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::class,
101 'args' => [ [
102 'authoritative' => false,
103 ] ],
104 ],
105 [
106 'class' => MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider::class,
107 'args' => [ [
108 'authoritative' => true,
109 ] ],
110 ],
111 ],
112 'secondaryauth' => [],
113 ];
114
115 // T46192 Do not attempt to send a real e-mail
116 Hooks::clear( 'AlternateUserMailer' );
117 Hooks::register(
118 'AlternateUserMailer',
119 function () {
120 return false;
121 }
122 );
123 // xdebug's default of 100 is too low for MediaWiki
124 ini_set( 'xdebug.max_nesting_level', 1000 );
125
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 );
130 }
131
132 }