4 * This file is PHPUnit autoload file for PhpStorm IDE and other JetBrains IDEs.
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.
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.
15 * PS: Mostly it is copy-paste from `phpunit.php` and `doMaintenance.php`.
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
;
26 $argv[2] = getenv( 'WIKI_NAME' ) ?
: 'wiki';
28 require_once __DIR__
. "/phpunit.php";
30 // Get an object to start us off
31 /** @var Maintenance $maintenance */
32 $maintenance = new PHPUnitMaintClass();
34 // Basic sanity checks and such
35 $maintenance->setup();
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();
41 # Start the autoloader, so that extensions can derive classes from core files
42 require_once "$IP/includes/AutoLoader.php";
46 if ( file_exists( "$IP/StartProfiler.php" ) ) {
47 require "$IP/StartProfiler.php";
50 $requireOnceGlobalsScope = function ( $file ) use ( $self ) {
51 foreach ( array_keys( $GLOBALS ) as $varName ) {
52 eval( sprintf( 'global $%s;', $varName ) );
58 $definedVars = get_defined_vars();
59 foreach ( $definedVars as $varName => $value ) {
60 eval( sprintf( 'global $%s; $%s = $value;', $varName, $varName ) );
64 // Some other requires
65 $requireOnceGlobalsScope( "$IP/includes/Defines.php" );
66 $requireOnceGlobalsScope( "$IP/includes/DefaultSettings.php" );
67 $requireOnceGlobalsScope( "$IP/includes/GlobalFunctions.php" );
69 foreach ( array_keys( $GLOBALS ) as $varName ) {
70 eval( sprintf( 'global $%s;', $varName ) );
73 # Load composer's autoloader if present
74 if ( is_readable( "$IP/vendor/autoload.php" ) ) {
75 require_once "$IP/vendor/autoload.php";
78 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
79 # Use a callback function to configure MediaWiki
80 call_user_func( MW_CONFIG_CALLBACK
);
82 // Require the configuration (probably LocalSettings.php)
83 require $maintenance->loadSettings();
86 if ( $maintenance->getDbType() === Maintenance
::DB_NONE
) {
88 $wgLocalisationCacheConf['storeClass'] === false
90 $wgLocalisationCacheConf['store'] == 'db'
91 ||
( $wgLocalisationCacheConf['store'] == 'detect' && !$wgCacheDirectory )
94 $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull';
98 $maintenance->finalSetup();
100 $requireOnceGlobalsScope( "$IP/includes/Setup.php" );
102 // Initialize main config instance
103 $maintenance->setConfig( MediaWikiServices
::getInstance()->getMainConfig() );
105 // Sanity-check required extensions are installed
106 $maintenance->checkRequiredExtensions();
108 // A good time when no DBs have writes pending is around lag checks.
109 // This avoids having long running scripts just OOM and lose all the updates.
110 $maintenance->setAgentAndTriggers();