public function DrupalUnitTestBase::containerBuild

Sets up the base service container for this test.

Extend this method in your test to register additional service overrides that need to persist a DrupalKernel reboot. This method is only called once for each test.

See also

DrupalUnitTestBase::setUp()

DrupalUnitTestBase::enableModules()

1 call to DrupalUnitTestBase::containerBuild()
DrupalUnitTestBase::setUp in drupal/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
Sets up Drupal unit test environment.

File

drupal/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php, line 121
Contains Drupal\simpletest\DrupalUnitTestBase.

Class

DrupalUnitTestBase
Base test case class for Drupal unit tests.

Namespace

Drupal\simpletest

Code

public function containerBuild($container) {
  global $conf;

  // Keep the container object around for tests.
  $this->container = $container;
  $conf['lock_backend'] = 'Drupal\\Core\\Lock\\NullLockBackend';
  $conf['cache_classes'] = array(
    'cache' => 'Drupal\\Core\\Cache\\MemoryBackend',
  );
  $container
    ->register('config.storage', 'Drupal\\Core\\Config\\FileStorage')
    ->addArgument($this->configDirectories[CONFIG_ACTIVE_DIRECTORY]);
  $conf['keyvalue_default'] = 'keyvalue.memory';
  $container
    ->register('keyvalue.memory', 'Drupal\\Core\\KeyValueStore\\KeyValueMemoryFactory');
  if (!$container
    ->has('keyvalue')) {

    // TestBase::setUp puts a completely empty container in
    // drupal_container() which is somewhat the mirror of the empty
    // environment being set up. Unit tests need not to waste time with
    // getting a container set up for them. Drupal Unit Tests might just get
    // away with a simple container holding the absolute bare minimum. When
    // a kernel is overridden then there's no need to re-register the keyvalue
    // service but when a test is happy with the superminimal container put
    // together here, it still might a keyvalue storage for anything (for
    // eg. module_enable) using state() -- that's why a memory service was
    // added in the first place.
    $container
      ->register('keyvalue', 'Drupal\\Core\\KeyValueStore\\KeyValueFactory')
      ->addArgument(new Reference('service_container'));
  }
}