MediaWiki  1.28.0
TestSetup.php
Go to the documentation of this file.
1 <?php
2 
4 
8 class TestSetup {
13  public static function applyInitialConfig() {
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 =
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  [
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  [
75  'args' => [ [
76  'authoritative' => false,
77  ] ],
78  ],
79  [
81  'args' => [ [
82  'authoritative' => true,
83  ] ],
84  ],
85  ],
86  'secondaryauth' => [],
87  ];
89 
90  // Bug 44192 Do not attempt to send a real e-mail
91  Hooks::clear( 'AlternateUserMailer' );
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 }
$wgMainStash
Main object stash type.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
$wgMainWANCache
Main Wide-Area-Network cache type.
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
$wgSessionPbkdf2Iterations
Number of internal PBKDF2 iterations to use when deriving session secrets.
static register($name, $callback)
Attach an event handler to a given hook.
Definition: Hooks.php:49
Backwards-compatibility wrapper for AuthManager via $wgAuth.
$wgParserCacheType
The cache type for storing article HTML.
static clear($name)
Clears hooks registered via Hooks::register().
Definition: Hooks.php:66
$wgLocalisationCacheConf
Localisation cache configuration.
$wgMessageCacheType
The cache type for storing the contents of the MediaWiki namespace.
$wgUseDatabaseMessages
Translation using MediaWiki: namespace.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same so they can t rely on Unix and must forbid reads to even standard directories like tmp lest users read each others files We cannot assume that the user has the ability to install or run any programs not written as web accessible PHP scripts Since anything that works on cheap shared hosting will work if you have shell or root access MediaWiki s design is based around catering to the lowest common denominator Although we support higher end setups as the way many things work by default is tailored toward shared hosting These defaults are unconventional from the point of view of and they certainly aren t ideal for someone who s installing MediaWiki as MediaWiki does not conform to normal Unix filesystem layout Hopefully we ll offer direct support for standard layouts in the future
CACHE_MEMCACHED $wgMainCacheType
Definition: memcached.txt:63
$wgLanguageConverterCacheType
The cache type for storing language conversion tables, which are used when parsing certain text and i...
$wgLocaltimezone
Fake out the timezone that the server thinks it's in.
$wgSessionCacheType
The cache type for storing session data.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
const CACHE_NONE
Definition: Defines.php:94
static applyInitialConfig()
This should be called before Setup.php, e.g.
Definition: TestSetup.php:13
Common code for test environment initialisation and teardown.
Definition: TestSetup.php:8