You are here

protected function WebTestBase::installModulesFromClassProperty in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/WebTestBase.php \Drupal\simpletest\WebTestBase::installModulesFromClassProperty()

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

Parameters

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

1 call to WebTestBase::installModulesFromClassProperty()
WebTestBase::setUp in core/modules/simpletest/src/WebTestBase.php
Sets up a Drupal site for running functional and integration tests.

File

core/modules/simpletest/src/WebTestBase.php, line 1016
Contains \Drupal\simpletest\WebTestBase.

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

Code

protected function installModulesFromClassProperty(ContainerInterface $container) {
  $class = get_class($this);
  $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, SafeMarkup::format('Enabled modules: %modules', [
        '%modules' => implode(', ', $modules),
      ]));
    } catch (MissingDependencyException $e) {

      // The exception message has all the details.
      $this
        ->fail($e
        ->getMessage());
    }
    $this
      ->rebuildContainer();
  }
}