4 * PHPUnit bootstrap file.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
25 if ( PHP_SAPI
!== 'cli' ) {
26 die( 'This file is only meant to be executed indirectly by PHPUnit\'s bootstrap process!' );
30 * PHPUnit includes the bootstrap file inside a method body, while most MediaWiki startup files
31 * assume to be included in the global scope.
32 * This utility provides a way to include these files: it makes all globals available in the
33 * inclusion scope before including the file, then exports all new or changed globals.
35 * @param string $fileName the file to include
37 function wfRequireOnceInGlobalScope( $fileName ) {
38 // phpcs:disable MediaWiki.Usage.ForbiddenFunctions.extract
39 extract( $GLOBALS, EXTR_REFS | EXTR_SKIP
);
42 require_once $fileName;
44 foreach ( get_defined_vars() as $varName => $value ) {
45 $GLOBALS[$varName] = $value;
49 define( 'MEDIAWIKI', true );
50 define( 'MW_PHPUNIT_TEST', true );
52 // We don't use a settings file here but some code still assumes that one exists
53 define( 'MW_CONFIG_FILE', 'LocalSettings.php' );
55 $IP = realpath( __DIR__
. '/../../' );
57 // these variables must be defined before setup runs
59 // Faking for Setup.php
60 $GLOBALS['wgScopeTest'] = 'MediaWiki Setup.php scope test';
61 $GLOBALS['wgCommandLineMode'] = true;
62 $GLOBALS['wgAutoloadClasses'] = [];
64 require_once "$IP/tests/common/TestSetup.php";
66 wfRequireOnceInGlobalScope( "$IP/includes/AutoLoader.php" );
67 wfRequireOnceInGlobalScope( "$IP/tests/common/TestsAutoLoader.php" );
68 wfRequireOnceInGlobalScope( "$IP/includes/Defines.php" );
69 wfRequireOnceInGlobalScope( "$IP/includes/DefaultSettings.php" );
71 // Load extensions/skins present in filesystem so that classes can be discovered.
72 $directoryToJsonMap = [
73 'extensions' => [ 'extension.json', 'extension-wip.json' ],
74 'skins' => [ 'skin.json', 'skin-wip.json' ]
76 foreach ( $directoryToJsonMap as $directory => $jsonFile ) {
77 foreach ( new DirectoryIterator( __DIR__
. '/../../' . $directory ) as $iterator ) {
78 foreach ( $jsonFile as $file ) {
79 $jsonPath = $iterator->getPathname() . '/' . $file;
80 if ( file_exists( $jsonPath ) ) {
81 $json = file_get_contents( $jsonPath );
82 $info = json_decode( $json, true );
83 $dir = dirname( $jsonPath );
84 ExtensionRegistry
::exportAutoloadClassesAndNamespaces( $dir, $info );