function I18nQueryTraitTest::disablePsr4ForUninstalledModules
Removes PSR-4 namespaces from class loader for uninstalled modules.
TestRunnerKernel registers namespaces for all modules, including uninstalled modules. This method removes the PSR-4 namespace for the list of modules passed in after confirming they are all uninstalled.
Parameters
string[] $remove_psr4_modules: List of machine names of modules that are uninstalled and whose PSR-4 namespaces should be removed from the class loader.
1 call to I18nQueryTraitTest::disablePsr4ForUninstalledModules()
- I18nQueryTraitTest::testMigrateSourcePluginUsingI18nQueryTraitDiscovery in core/
modules/ migrate_drupal/ tests/ src/ Kernel/ I18nQueryTraitTest.php - Tests instantiating migrate source plugins using I18nQueryTrait.
File
-
core/
modules/ migrate_drupal/ tests/ src/ Kernel/ I18nQueryTraitTest.php, line 61
Class
- I18nQueryTraitTest
- Tests instantiating migrate source plugins using I18nQueryTrait.
Namespace
Drupal\Tests\migrate_drupal\KernelCode
protected function disablePsr4ForUninstalledModules(array $remove_psr4_modules) : void {
/** @var \Drupal\Core\Extension\ModuleExtensionList $module_list */
$module_list = \Drupal::service('extension.list.module');
$available_modules = $module_list->getAllAvailableInfo();
$installed_modules = $module_list->getAllInstalledInfo();
$prefixes = $this->classLoader
->getPrefixesPsr4();
foreach ($remove_psr4_modules as $module) {
$this->assertArrayHasKey($module, $available_modules);
$this->assertArrayNotHasKey($module, $installed_modules);
if (isset($prefixes["Drupal\\{$module}\\"])) {
// Cannot actually remove the PSR4 prefix from the class loader, so set
// the path to a wrong location.
$this->classLoader
->setPsr4("Drupal\\{$module}\\", '');
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.