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.
8 * @param string $fileName the file to include
10 function wfRequireOnceInGlobalScope( $fileName ) {
11 // phpcs:disable MediaWiki.Usage.ForbiddenFunctions.extract
12 extract( $GLOBALS, EXTR_REFS | EXTR_SKIP
);
15 require_once $fileName;
17 foreach ( get_defined_vars() as $varName => $value ) {
18 $GLOBALS[$varName] = $value;
22 define( 'MEDIAWIKI', true );
23 define( 'MW_PHPUNIT_TEST', true );
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' );
30 $IP = realpath( __DIR__
. '/../../..' );
32 // these variables must be defined before setup runs
34 $GLOBALS['wgCommandLineMode'] = true;
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';
41 require_once "$IP/tests/common/TestSetup.php";
43 wfRequireOnceInGlobalScope( "$IP/includes/AutoLoader.php" );
44 wfRequireOnceInGlobalScope( "$IP/includes/Defines.php" );
45 wfRequireOnceInGlobalScope( "$IP/includes/DefaultSettings.php" );
46 wfRequireOnceInGlobalScope( "$IP/includes/Setup.php" );
48 require_once "$IP/tests/common/TestsAutoLoader.php";
50 // Remove MWExceptionHandler's handling of PHP errors to allow PHPUnit to replace them
51 restore_error_handler();
53 unset( $GLOBALS['wgScopeTest'] );
55 // Disable all database connections
56 \MediaWiki\MediaWikiServices
::disableStorageBackend();