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