258c82255308a95682164f799f8843fd44ce79e8
[lhc/web/wiklou.git] / tests / phpunit / bootstrap.php
1 <?php
2
3 /**
4 * PHPUnit bootstrap file.
5 *
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.
10 *
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.
15 *
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
20 *
21 * @file
22 * @ingroup Testing
23 */
24
25 if ( PHP_SAPI !== 'cli' ) {
26 die( 'This file is only meant to be executed indirectly by PHPUnit\'s bootstrap process!' );
27 }
28
29 /**
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.
34 *
35 * @param string $fileName the file to include
36 */
37 function wfRequireOnceInGlobalScope( $fileName ) {
38 // phpcs:disable MediaWiki.Usage.ForbiddenFunctions.extract
39 extract( $GLOBALS, EXTR_REFS | EXTR_SKIP );
40 // phpcs:enable
41
42 require_once $fileName;
43
44 foreach ( get_defined_vars() as $varName => $value ) {
45 $GLOBALS[$varName] = $value;
46 }
47 }
48
49 define( 'MEDIAWIKI', true );
50 define( 'MW_PHPUNIT_TEST', true );
51
52 // We don't use a settings file here but some code still assumes that one exists
53 define( 'MW_CONFIG_FILE', 'LocalSettings.php' );
54
55 $IP = realpath( __DIR__ . '/../../' );
56
57 // these variables must be defined before setup runs
58 $GLOBALS['IP'] = $IP;
59 // Faking for Setup.php
60 $GLOBALS['wgScopeTest'] = 'MediaWiki Setup.php scope test';
61 $GLOBALS['wgCommandLineMode'] = true;
62 $GLOBALS['wgAutoloadClasses'] = [];
63
64 require_once "$IP/tests/common/TestSetup.php";
65
66 wfRequireOnceInGlobalScope( "$IP/includes/AutoLoader.php" );
67 wfRequireOnceInGlobalScope( "$IP/tests/common/TestsAutoLoader.php" );