wiki.techinc.nl/tests/phpunit/getPHPUnitExtensionsAndSkins.php
Daimona Eaytoy 539023e3cb phpunit: Make getPHPUnitExtensionsAndSkins run the UnitTestsList hook
In a future with a single bootstrap and config, we won't be able to run
hooks as early as in ExtensionTestSuite::suite. On top of that, if the
config file does not fully load the MW config (as is the case with
bootstrap.php), it won't even be possible to run hooks at all.

So move the relevant code from ExtensionsTestSuite to
getPHPUnitExtensionsAndSkins, collect the output in bootstrap.php and
pass it to ExtensionsTestSuite.

This hack wouldn't be necessary if the UnitTestList hook didn't exist,
but fortunately there are plans to get rid of it (T298509).

Keep the old code in place when entering from an entry point that
doesn't load bootstrap.php (i.e., phpunit.php and composer
phpunit:entrypoint).

Bug: T227900
Change-Id: Idf72db24dbd66bb66baf51564a7504d2bc035e8c
2023-11-13 15:12:55 +01:00

44 lines
2 KiB
PHP
Executable file

#!/usr/bin/env php
<?php
/**
* WARNING: Hic sunt dracones!
*
* This script is used in the PHPUnit bootstrap to get a list of extensions and skins to autoload,
* without having the bootstrap file itself load any settings. It is a HUGE but unavoidable hack,
* if we want to avoid loading settings in unit tests, and at the same time only load the extensions
* enabled in LocalSettings.php without triggering any other side effects of Setup.php and the other
* files it includes.
* One day this may become unnecessary if we enforce YAML settings with a static list of extensions
* and skins (https://www.mediawiki.org/wiki/Manual:YAML_settings_file_format).
* The script was introduced for T227900, the idea being to have a single config file that can be used
* with both unit and integration tests.
* @internal This script should only be invoked by bootstrap.php, as part of the PHPUnit bootstrap process
*/
use MediaWiki\HookContainer\HookRunner;
use MediaWiki\MediaWikiServices;
require_once __DIR__ . '/bootstrap.common.php';
TestSetup::loadSettingsFiles();
$extensionsAndSkins = ExtensionRegistry::getInstance()->getQueue();
echo implode( "\n", array_keys( $extensionsAndSkins ) );
echo "\n\nTESTPATHS\n\n";
// Build a list of extension tests, based on autodiscovered tests as well as tests added with the
// UnitTestsList hook. The list is only to be used in ExtensionsTestSuite.
// This is a hack inside the hack, motivated by the fact that we can't access MediaWikiServices, or even
// just the config needed to create a hook container, as early as when ExtensionsTestSuite::suite is called.
// This particular hack can be removed once the UnitTestsList hook is removed (T298509)
$registry = ExtensionRegistry::getInstance();
foreach ( $registry->getAllThings() as $info ) {
$paths[] = dirname( $info['path'] ) . '/tests/phpunit';
}
// Extensions can return a list of files or directories
( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onUnitTestsList( $paths );
echo implode( "\n", $paths );