TestSetup.php 3.2 KB

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