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