Use setContentLang() instead of setMwGlobals()
[lhc/web/wiklou.git] / tests / phpunit / autoload.ide.php
1 <?php
2
3 /**
4 * This file is PHPUnit autoload file for PhpStorm IDE and other JetBrains IDEs.
5 *
6 * This file should be set in `Languages and frameworks > PHP > PhpUnit`
7 * select `Use Composer autoloader` and set `Path to script` to `<path to this file>`.
8 * After that, tests can be run in PhpStorm using Right-click > Run or `Ctrl + Shift + F10`.
9 * Also, tests can be run with debugger very easily.
10 *
11 * This file basically does almost the same thing as `tests/phpunit/phpunit.php`, except that all
12 * code is going to be executed inside some function, so some hacks needed to make old code to be
13 * executed as if it was executed on top of the execution stack.
14 *
15 * PS: Mostly it is copy-paste from `phpunit.php` and `doMaintenance.php`.
16 *
17 * @file
18 */
19
20 // Set a flag which can be used to detect when other scripts have been entered
21 // through this entry point or not.
22 use MediaWiki\MediaWikiServices;
23
24 global $argv;
25 $argv[1] = '--wiki';
26 $argv[2] = getenv( 'WIKI_NAME' ) ?: 'wiki';
27
28 require_once __DIR__ . "/phpunit.php";
29
30 // Get an object to start us off
31 /** @var Maintenance $maintenance */
32 $maintenance = new PHPUnitMaintClass();
33
34 // Basic sanity checks and such
35 $maintenance->setup();
36
37 // We used to call this variable $self, but it was moved
38 // to $maintenance->mSelf. Keep that here for b/c
39 $self = $maintenance->getName();
40 # Start the autoloader, so that extensions can derive classes from core files
41 require_once "$IP/includes/AutoLoader.php";
42
43 $requireOnceGlobalsScope = function ( $file ) use ( $self ) {
44 foreach ( array_keys( $GLOBALS ) as $varName ) {
45 eval( sprintf( 'global $%s;', $varName ) );
46 }
47
48 require_once $file;
49
50 unset( $file );
51 $definedVars = get_defined_vars();
52 foreach ( $definedVars as $varName => $value ) {
53 eval( sprintf( 'global $%s; $%s = $value;', $varName, $varName ) );
54 }
55 };
56
57 // Some other requires
58 $requireOnceGlobalsScope( "$IP/includes/Defines.php" );
59 $requireOnceGlobalsScope( "$IP/includes/DefaultSettings.php" );
60 $requireOnceGlobalsScope( "$IP/includes/GlobalFunctions.php" );
61
62 foreach ( array_keys( $GLOBALS ) as $varName ) {
63 eval( sprintf( 'global $%s;', $varName ) );
64 }
65
66 # Load composer's autoloader if present
67 if ( is_readable( "$IP/vendor/autoload.php" ) ) {
68 require_once "$IP/vendor/autoload.php";
69 }
70
71 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
72 # Use a callback function to configure MediaWiki
73 call_user_func( MW_CONFIG_CALLBACK );
74 } else {
75 // Require the configuration (probably LocalSettings.php)
76 require $maintenance->loadSettings();
77 }
78
79 if ( $maintenance->getDbType() === Maintenance::DB_NONE ) {
80 if (
81 $wgLocalisationCacheConf['storeClass'] === false
82 && (
83 $wgLocalisationCacheConf['store'] == 'db'
84 || ( $wgLocalisationCacheConf['store'] == 'detect' && !$wgCacheDirectory )
85 )
86 ) {
87 $wgLocalisationCacheConf['storeClass'] = LCStoreNull::class;
88 }
89 }
90
91 $maintenance->finalSetup();
92 // Some last includes
93 $requireOnceGlobalsScope( "$IP/includes/Setup.php" );
94
95 // Initialize main config instance
96 $maintenance->setConfig( MediaWikiServices::getInstance()->getMainConfig() );
97
98 // Sanity-check required extensions are installed
99 $maintenance->checkRequiredExtensions();
100
101 // A good time when no DBs have writes pending is around lag checks.
102 // This avoids having long running scripts just OOM and lose all the updates.
103 $maintenance->setAgentAndTriggers();