function FunctionalTestSetupTrait::installModulesFromClassProperty

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::installModulesFromClassProperty()
  2. 10 core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::installModulesFromClassProperty()
  3. 11.x core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::installModulesFromClassProperty()

Install modules defined by `static::$modules`.

To install test modules outside of the testing environment, add

$settings['extension_discovery_scan_tests'] = TRUE;

to your settings.php.

Parameters

\Symfony\Component\DependencyInjection\ContainerInterface $container: The container.

2 calls to FunctionalTestSetupTrait::installModulesFromClassProperty()
BrowserTestBase::installDrupal in core/tests/Drupal/Tests/BrowserTestBase.php
Installs Drupal into the Simpletest site.
WebDriverTestBase::installModulesFromClassProperty in core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php
Install modules defined by `static::$modules`.
1 method overrides FunctionalTestSetupTrait::installModulesFromClassProperty()
WebDriverTestBase::installModulesFromClassProperty in core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php
Install modules defined by `static::$modules`.

File

core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php, line 462

Class

FunctionalTestSetupTrait
Defines a trait for shared functional test setup functionality.

Namespace

Drupal\Core\Test

Code

protected function installModulesFromClassProperty(ContainerInterface $container) {
    $class = static::class;
    $modules = [];
    while ($class) {
        if (property_exists($class, 'modules')) {
            $modules = array_merge($modules, $class::$modules);
        }
        $class = get_parent_class($class);
    }
    if ($modules) {
        $modules = array_unique($modules);
        try {
            $success = $container->get('module_installer')
                ->install($modules, TRUE);
            $this->assertTrue($success, new FormattableMarkup('Enabled modules: %modules', [
                '%modules' => implode(', ', $modules),
            ]));
        } catch (MissingDependencyException $e) {
            // The exception message has all the details.
            $this->fail($e->getMessage());
        }
        // The container was already rebuilt by the ModuleInstaller.
        $this->container = \Drupal::getContainer();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.