Separate MediaWiki unit and integration tests
[lhc/web/wiklou.git] / tests / phpunit / unit / initUnitTests.php
1 <?php
2
3 /**
4 * Allows to include a file that assumes to be included in the file scope.
5 * It makes all globals available in the inclusion scope before including the file,
6 * then exports all new globals.
7 *
8 * @param string $fileName the file to include
9 */
10 function wfRequireOnceInGlobalScope( $fileName ) {
11 // phpcs:disable MediaWiki.Usage.ForbiddenFunctions.extract
12 extract( $GLOBALS, EXTR_REFS | EXTR_SKIP );
13 // phpcs:enable
14
15 require_once $fileName;
16
17 foreach ( get_defined_vars() as $varName => $value ) {
18 $GLOBALS[$varName] = $value;
19 }
20 }
21
22 define( 'MEDIAWIKI', true );
23 define( 'MW_PHPUNIT_TEST', true );
24
25 // Inject test configuration via callback, bypassing LocalSettings.php
26 define( 'MW_CONFIG_CALLBACK', '\TestSetup::applyInitialConfig' );
27 // We don't use a settings file here but some code still assumes that one exists
28 define( 'MW_CONFIG_FILE', 'LocalSettings.php' );
29
30 $IP = realpath( __DIR__ . '/../../..' );
31
32 // these variables must be defined before setup runs
33 $GLOBALS['IP'] = $IP;
34 $GLOBALS['wgCommandLineMode'] = true;
35
36 // Bypass Setup.php's scope test
37 $GLOBALS['wgScopeTest'] = 'MediaWiki Setup.php scope test';
38 // Avoid PHP Notice in Setup.php
39 $GLOBALS['self'] = 'Unit tests';
40
41 require_once "$IP/tests/common/TestSetup.php";
42
43 wfRequireOnceInGlobalScope( "$IP/includes/AutoLoader.php" );
44 wfRequireOnceInGlobalScope( "$IP/includes/Defines.php" );
45 wfRequireOnceInGlobalScope( "$IP/includes/DefaultSettings.php" );
46 wfRequireOnceInGlobalScope( "$IP/includes/Setup.php" );
47
48 require_once "$IP/tests/common/TestsAutoLoader.php";
49
50 // Remove MWExceptionHandler's handling of PHP errors to allow PHPUnit to replace them
51 restore_error_handler();
52
53 unset( $GLOBALS['wgScopeTest'] );
54
55 // Disable all database connections
56 \MediaWiki\MediaWikiServices::disableStorageBackend();