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