53e724bbed8d69c766a5d9d84bdf088d428921c4
[lhc/web/wiklou.git] / tests / common / TestSetup.php
1 <?php
2
3 use MediaWiki\MediaWikiServices;
4
5 /**
6 * Common code for test environment initialisation and teardown
7 */
8 class TestSetup {
9 /**
10 * This should be called before Setup.php, e.g. from the finalSetup() method
11 * of a Maintenance subclass
12 */
13 public static function applyInitialConfig() {
14 global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgMainWANCache;
15 global $wgMainStash;
16 global $wgLanguageConverterCacheType, $wgUseDatabaseMessages;
17 global $wgLocaltimezone, $wgLocalisationCacheConf;
18 global $wgSearchType;
19 global $wgDevelopmentWarnings;
20 global $wgSessionProviders, $wgSessionPbkdf2Iterations;
21 global $wgJobTypeConf;
22 global $wgAuthManagerConfig, $wgAuth;
23
24 // wfWarn should cause tests to fail
25 $wgDevelopmentWarnings = true;
26
27 // Make sure all caches and stashes are either disabled or use
28 // in-process cache only to prevent tests from using any preconfigured
29 // cache meant for the local wiki from outside the test run.
30 // See also MediaWikiTestCase::run() which mocks CACHE_DB and APC.
31
32 // Disabled in DefaultSettings, override local settings
33 $wgMainWANCache =
34 $wgMainCacheType = CACHE_NONE;
35 // Uses CACHE_ANYTHING in DefaultSettings, use hash instead of db
36 $wgMessageCacheType =
37 $wgParserCacheType =
38 $wgSessionCacheType =
39 $wgLanguageConverterCacheType = 'hash';
40 // Uses db-replicated in DefaultSettings
41 $wgMainStash = 'hash';
42 // Use memory job queue
43 $wgJobTypeConf = [
44 'default' => [ 'class' => 'JobQueueMemory', 'order' => 'fifo' ],
45 ];
46
47 $wgUseDatabaseMessages = false; # Set for future resets
48
49 // Assume UTC for testing purposes
50 $wgLocaltimezone = 'UTC';
51
52 $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull';
53
54 // Do not bother updating search tables
55 $wgSearchType = 'SearchEngineDummy';
56
57 // Generic MediaWiki\Session\SessionManager configuration for tests
58 // We use CookieSessionProvider because things might be expecting
59 // cookies to show up in a FauxRequest somewhere.
60 $wgSessionProviders = [
61 [
62 'class' => MediaWiki\Session\CookieSessionProvider::class,
63 'args' => [ [
64 'priority' => 30,
65 'callUserSetCookiesHook' => true,
66 ] ],
67 ],
68 ];
69
70 // Single-iteration PBKDF2 session secret derivation, for speed.
71 $wgSessionPbkdf2Iterations = 1;
72
73 // Generic AuthManager configuration for testing
74 $wgAuthManagerConfig = [
75 'preauth' => [],
76 'primaryauth' => [
77 [
78 'class' => MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::class,
79 'args' => [ [
80 'authoritative' => false,
81 ] ],
82 ],
83 [
84 'class' => MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider::class,
85 'args' => [ [
86 'authoritative' => true,
87 ] ],
88 ],
89 ],
90 'secondaryauth' => [],
91 ];
92 $wgAuth = new MediaWiki\Auth\AuthManagerAuthPlugin();
93
94 // Bug 44192 Do not attempt to send a real e-mail
95 Hooks::clear( 'AlternateUserMailer' );
96 Hooks::register(
97 'AlternateUserMailer',
98 function () {
99 return false;
100 }
101 );
102 // xdebug's default of 100 is too low for MediaWiki
103 ini_set( 'xdebug.max_nesting_level', 1000 );
104
105 // Bug T116683 serialize_precision of 100
106 // may break testing against floating point values
107 // treated with PHP's serialize()
108 ini_set( 'serialize_precision', 17 );
109
110 // TODO: we should call MediaWikiTestCase::prepareServices( new GlobalVarConfig() ) here.
111 // But PHPUnit may not be loaded yet, so we have to wait until just
112 // before PHPUnit_TextUI_Command::main() is executed.
113 }
114
115 }