Debian Codegraph @

tests/phpunit/getPHPUnitExtensionsAndSkins.php

raw symbols SCIP
1 #!/usr/bin/env php
2 <?php
3
4 /**
5 * WARNING: Hic sunt dracones!
6 *
7 * This script is used in the PHPUnit bootstrap to get a list of extensions and skins to autoload,
8 * without having the bootstrap file itself load any settings. It is a HUGE but unavoidable hack,
9 * if we want to avoid loading settings in unit tests, and at the same time only load the extensions
10 * enabled in LocalSettings.php without triggering any other side effects of Setup.php and the other
11 * files it includes.
12 * One day this may become unnecessary if we enforce YAML settings with a static list of extensions
13 * and skins (https://www.mediawiki.org/wiki/Manual:YAML_settings_file_format).
14 * The script was introduced for T227900, the idea being to have a single config file that can be used
15 * with both unit and integration tests.
16 * @internal This script should only be invoked by bootstrap.php, as part of the PHPUnit bootstrap process
17 */
18
19 use MediaWiki\HookContainer\HookRunner;
20 use MediaWiki\MediaWikiServices;
21 use MediaWiki\Registration\ExtensionRegistry;
22
23 require_once __DIR__ . '/bootstrap.common.php';
24
25 TestSetup::loadSettingsFiles();
26
27 $extensionsAndSkins = ExtensionRegistry::getInstance()->getQueue();
28
29 echo implode( "\n", array_keys( $extensionsAndSkins ) );
30
31 echo "\n\nTESTPATHS\n\n";
32
33 // Build a list of extension tests, based on autodiscovered tests as well as tests added with the
34 // UnitTestsList hook. The list is only to be used in ExtensionsTestSuite.
35 // This is a hack inside the hack, motivated by the fact that we can't access MediaWikiServices, or even
36 // just the config needed to create a hook container, as early as when ExtensionsTestSuite::suite is called.
37 // This particular hack can be removed once the UnitTestsList hook is removed (T298509)
38 $registry = ExtensionRegistry::getInstance();
39 $paths = [];
40 foreach ( $registry->getAllThings() as $info ) {
41 $paths[] = dirname( $info['path'] ) . '/tests/phpunit';
42 }
43 // Extensions can return a list of files or directories
44 ( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onUnitTestsList( $paths );
45
46 echo implode( "\n", $paths );