3 * PHPUnit bootstrap file for the unit test suite.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 if ( PHP_SAPI
!== 'cli' ) {
25 die( 'This file is only meant to be executed indirectly by PHPUnit\'s bootstrap process!' );
29 * PHPUnit includes the bootstrap file inside a method body, while most MediaWiki startup files
30 * assume to be included in the global scope.
31 * This utility provides a way to include these files: it makes all globals available in the
32 * inclusion scope before including the file, then exports all new or changed globals.
34 * @param string $fileName the file to include
36 function wfRequireOnceInGlobalScope( $fileName ) {
37 // phpcs:disable MediaWiki.Usage.ForbiddenFunctions.extract
38 extract( $GLOBALS, EXTR_REFS | EXTR_SKIP
);
41 require_once $fileName;
43 foreach ( get_defined_vars() as $varName => $value ) {
44 $GLOBALS[$varName] = $value;
48 define( 'MEDIAWIKI', true );
49 define( 'MW_PHPUNIT_TEST', true );
51 // We don't use a settings file here but some code still assumes that one exists
52 define( 'MW_CONFIG_FILE', 'LocalSettings.php' );
54 $IP = realpath( __DIR__
. '/../../..' );
56 // these variables must be defined before setup runs
58 $GLOBALS['wgCommandLineMode'] = true;
60 require_once "$IP/tests/common/TestSetup.php";
62 wfRequireOnceInGlobalScope( "$IP/includes/AutoLoader.php" );
63 wfRequireOnceInGlobalScope( "$IP/includes/Defines.php" );
64 wfRequireOnceInGlobalScope( "$IP/includes/DefaultSettings.php" );
65 wfRequireOnceInGlobalScope( "$IP/includes/GlobalFunctions.php" );
67 require_once "$IP/tests/common/TestsAutoLoader.php";
69 TestSetup
::applyInitialConfig();