fromParameters( $GLOBALS['argv'], $paratestArgs ); if ( $phpunitArgs->hasArgument() ) { // A test or test directory was specified explicitly. Normalize line endings and case, and see if we likely // got a directory of unit tests only (or a file therein). $testArgument = strtolower( strtr( $phpunitArgs->argument(), '\\', '/' ) ); $hasIntegrationTests = !( str_contains( $testArgument, '/unit/' ) || str_ends_with( $testArgument, '/unit' ) ); } elseif ( $phpunitArgs->hasTestSuite() ) { // If only unit test suites are being run, there can't be integration tests. Otherwise, // there *might* be integration tests. // See TestSuiteMapper for handling of the 'testsuites' argument. $suites = explode( ',', $phpunitArgs->testSuite() ); $unitSuites = [ 'core:unit', 'extensions:unit', 'skins:unit' ]; $hasIntegrationTests = array_diff( $suites, $unitSuites ) !== []; } else { // Something more complex, just assume there might be integration tests $hasIntegrationTests = true; } } if ( !$hasIntegrationTests ) { fwrite( STDERR, "Running without MediaWiki settings because there are no integration tests\n" ); // Faking in lieu of Setup.php $GLOBALS['wgAutoloadClasses'] = []; TestSetup::requireOnceInGlobalScope( MW_INSTALL_PATH . "/includes/AutoLoader.php" ); TestSetup::requireOnceInGlobalScope( MW_INSTALL_PATH . "/tests/common/TestsAutoLoader.php" ); TestSetup::requireOnceInGlobalScope( MW_INSTALL_PATH . "/includes/Defines.php" ); TestSetup::requireOnceInGlobalScope( MW_INSTALL_PATH . "/includes/GlobalFunctions.php" ); // Extract the defaults into global variables. // NOTE: this does not apply any dynamic defaults. foreach ( MainConfigSchema::listDefaultValues( 'wg' ) as $var => $value ) { $GLOBALS[$var] = $value; } TestSetup::requireOnceInGlobalScope( MW_INSTALL_PATH . "/includes/DevelopmentSettings.php" ); TestSetup::applyInitialConfig(); // Shell out to another script that will give us a list of loaded extensions and skins. We need to do that in // another process, not in this one, because loading setting files may have non-trivial side effects that could be // hard to undo. This sucks, but there doesn't seem to be a way to get a list of extensions and skins without // loading all of MediaWiki, which we don't want to do for unit tests. // Disable XDEBUG, so it doesn't cause the sub-process to hang. T358097 $env = getenv(); unset( $env['XDEBUG_CONFIG'] ); unset( $env['XDEBUG_MODE'] ); unset( $env['XDEBUG_SESSION'] ); // phpcs:ignore MediaWiki.Usage.ForbiddenFunctions.proc_open $process = proc_open( PHP_BINARY . ' ' . __DIR__ . '/getPHPUnitExtensionsAndSkins.php', [ 0 => [ 'pipe', 'r' ], 1 => [ 'pipe', 'w' ], 2 => [ 'pipe', 'w' ] ], $pipes, null, $env ); $extensionData = stream_get_contents( $pipes[1] ); fclose( $pipes[1] ); $cmdErr = stream_get_contents( $pipes[2] ); fclose( $pipes[2] ); $exitCode = proc_close( $process ); if ( $exitCode !== 0 ) { echo "Cannot load list of extensions and skins. Output:\n$cmdErr\n"; exit( 1 ); } // For simplicity, getPHPUnitExtensionsAndSkins uses `\n\nTESTPATHS\n\n` to separate the lists of JSON files and // additional test paths, so split the output into the individual lists. [ $pathsToJsonFilesStr, $testPathsStr ] = explode( "\n\nTESTPATHS\n\n", $extensionData ); $pathsToJsonFiles = $pathsToJsonFilesStr ? explode( "\n", $pathsToJsonFilesStr ) : []; $testPaths = explode( "\n", $testPathsStr ); $extensionProcessor = new ExtensionProcessor(); foreach ( $pathsToJsonFiles as $filePath ) { $extensionProcessor->extractInfoFromFile( $filePath ); } $autoload = $extensionProcessor->getExtractedAutoloadInfo( true ); AutoLoader::loadFiles( $autoload['files'] ); AutoLoader::registerClasses( $autoload['classes'] ); AutoLoader::registerNamespaces( $autoload['namespaces'] ); // More faking in lieu of Setup.php Profiler::init( [] ); } else { fwrite( STDERR, "Running with MediaWiki settings because there might be integration tests\n" ); TestSetup::loadSettingsFiles(); $extensionRegistry = ExtensionRegistry::getInstance(); $extensionsAndSkins = $extensionRegistry->getQueue(); $pathsToJsonFiles = array_keys( $extensionsAndSkins ); $testPaths = []; foreach ( $extensionRegistry->getAllThings() as $info ) { $testPaths[] = dirname( $info['path'] ) . '/tests/phpunit'; } ( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onUnitTestsList( $testPaths ); } /** @internal For use in ExtensionsUnitTestSuite and SkinsUnitTestSuite only */ define( 'MW_PHPUNIT_EXTENSIONS_PATHS', array_map( 'dirname', $pathsToJsonFiles ) ); /** @internal For use in ExtensionsTestSuite only */ define( 'MW_PHPUNIT_EXTENSIONS_TEST_PATHS', $testPaths ); TestSetup::maybeCheckComposerLockUpToDate();