public function KernelTestBase::containerBuild in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/simpletest/src/KernelTestBase.php \Drupal\simpletest\KernelTestBase::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 called whenever the kernel is rebuilt.
See also
\Drupal\simpletest\KernelTestBase::setUp()
\Drupal\simpletest\KernelTestBase::enableModules()
\Drupal\simpletest\KernelTestBase::disableModules()
12 calls to KernelTestBase::containerBuild()
- CachedStorageTest::containerBuild in core/
modules/ config/ src/ Tests/ Storage/ CachedStorageTest.php - Sets up the base service container for this test.
- ContentNegotiationRoutingTest::containerBuild in core/
modules/ system/ src/ Tests/ Routing/ ContentNegotiationRoutingTest.php - Sets up the base service container for this test.
- DatabaseBackendTagTest::containerBuild in core/
modules/ system/ src/ Tests/ Cache/ DatabaseBackendTagTest.php - Sets up the base service container for this test.
- DatabaseStorageExpirableTest::containerBuild in core/
modules/ system/ src/ Tests/ KeyValueStore/ DatabaseStorageExpirableTest.php - Sets up the base service container for this test.
- DatabaseStorageTest::containerBuild in core/
modules/ system/ src/ Tests/ KeyValueStore/ DatabaseStorageTest.php - Sets up the base service container for this test.
12 methods override KernelTestBase::containerBuild()
- CachedStorageTest::containerBuild in core/
modules/ config/ src/ Tests/ Storage/ CachedStorageTest.php - Sets up the base service container for this test.
- ContentNegotiationRoutingTest::containerBuild in core/
modules/ system/ src/ Tests/ Routing/ ContentNegotiationRoutingTest.php - Sets up the base service container for this test.
- DatabaseBackendTagTest::containerBuild in core/
modules/ system/ src/ Tests/ Cache/ DatabaseBackendTagTest.php - Sets up the base service container for this test.
- DatabaseStorageExpirableTest::containerBuild in core/
modules/ system/ src/ Tests/ KeyValueStore/ DatabaseStorageExpirableTest.php - Sets up the base service container for this test.
- DatabaseStorageTest::containerBuild in core/
modules/ system/ src/ Tests/ KeyValueStore/ DatabaseStorageTest.php - Sets up the base service container for this test.
File
- core/
modules/ simpletest/ src/ KernelTestBase.php, line 306 - Contains \Drupal\simpletest\KernelTestBase.
Class
- KernelTestBase
- Base class for integration tests.
Namespace
Drupal\simpletestCode
public function containerBuild(ContainerBuilder $container) {
// Keep the container object around for tests.
$this->container = $container;
// Set the default language on the minimal container.
$this->container
->setParameter('language.default_values', $this
->defaultLanguageData());
$container
->register('lock', 'Drupal\\Core\\Lock\\NullLockBackend');
$container
->register('cache_factory', 'Drupal\\Core\\Cache\\MemoryBackendFactory');
$container
->register('config.storage', 'Drupal\\Core\\Config\\DatabaseStorage')
->addArgument(Database::getConnection())
->addArgument('config');
if ($this->strictConfigSchema) {
$container
->register('simpletest.config_schema_checker', 'Drupal\\Core\\Config\\Testing\\ConfigSchemaChecker')
->addArgument(new Reference('config.typed'))
->addArgument($this
->getConfigSchemaExclusions())
->addTag('event_subscriber');
}
$keyvalue_options = $container
->getParameter('factory.keyvalue') ?: array();
$keyvalue_options['default'] = 'keyvalue.memory';
$container
->setParameter('factory.keyvalue', $keyvalue_options);
$container
->set('keyvalue.memory', $this->keyValueFactory);
if (!$container
->has('keyvalue')) {
// TestBase::setUp puts a completely empty container in
// $this->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 using
// \Drupal::state() -- that's why a memory service was added in the first
// place.
$container
->register('settings', 'Drupal\\Core\\Site\\Settings')
->setFactoryClass('Drupal\\Core\\Site\\Settings')
->setFactoryMethod('getInstance');
$container
->register('keyvalue', 'Drupal\\Core\\KeyValueStore\\KeyValueFactory')
->addArgument(new Reference('service_container'))
->addArgument(new Parameter('factory.keyvalue'));
$container
->register('state', 'Drupal\\Core\\State\\State')
->addArgument(new Reference('keyvalue'));
}
if ($container
->hasDefinition('path_processor_alias')) {
// Prevent the alias-based path processor, which requires a url_alias db
// table, from being registered to the path processor manager. We do this
// by removing the tags that the compiler pass looks for. This means the
// url generator can safely be used within tests.
$definition = $container
->getDefinition('path_processor_alias');
$definition
->clearTag('path_processor_inbound')
->clearTag('path_processor_outbound');
}
if ($container
->hasDefinition('password')) {
$container
->getDefinition('password')
->setArguments(array(
1,
));
}
// Register the stream wrapper manager.
$container
->register('stream_wrapper_manager', 'Drupal\\Core\\StreamWrapper\\StreamWrapperManager')
->addArgument(new Reference('module_handler'))
->addMethodCall('setContainer', array(
new Reference('service_container'),
));
$request = Request::create('/');
$container
->get('request_stack')
->push($request);
}