141e307fbe4e911991937816db9bf48b23d85011
[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['storeClass'] = LCStoreNull::class;
74
75 // Do not bother updating search tables
76 $wgSearchType = SearchEngineDummy::class;
77
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 = [
82 [
83 'class' => MediaWiki\Session\CookieSessionProvider::class,
84 'args' => [ [
85 'priority' => 30,
86 'callUserSetCookiesHook' => true,
87 ] ],
88 ],
89 ];
90
91 // Single-iteration PBKDF2 session secret derivation, for speed.
92 $wgSessionPbkdf2Iterations = 1;
93
94 // Generic AuthManager configuration for testing
95 $wgAuthManagerConfig = [
96 'preauth' => [],
97 'primaryauth' => [
98 [
99 'class' => MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::class,
100 'args' => [ [
101 'authoritative' => false,
102 ] ],
103 ],
104 [
105 'class' => MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider::class,
106 'args' => [ [
107 'authoritative' => true,
108 ] ],
109 ],
110 ],
111 'secondaryauth' => [],
112 ];
113
114 // T46192 Do not attempt to send a real e-mail
115 Hooks::clear( 'AlternateUserMailer' );
116 Hooks::register(
117 'AlternateUserMailer',
118 function () {
119 return false;
120 }
121 );
122 // xdebug's default of 100 is too low for MediaWiki
123 ini_set( 'xdebug.max_nesting_level', 1000 );
124
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 );
129 }
130
131 }