function KernelTestBase::register
Same name in other branches
- 8.9.x core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::register()
- 10 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::register()
- 11.x core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::register()
Registers test-specific services.
Extend this method in your test to register additional services. This method is called whenever the kernel is rebuilt.
Parameters
\Drupal\Core\DependencyInjection\ContainerBuilder $container: The service container to enhance.
Overrides ServiceProviderInterface::register
See also
\Drupal\Tests\KernelTestBase::bootKernel()
26 calls to KernelTestBase::register()
- BaseThemeMissingTest::register in core/
tests/ Drupal/ KernelTests/ Core/ Theme/ BaseThemeMissingTest.php - Registers test-specific services.
- CacheCollectorTest::register in core/
tests/ Drupal/ KernelTests/ Core/ Cache/ CacheCollectorTest.php - Registers test-specific services.
- ContentNegotiationRoutingTest::register in core/
tests/ Drupal/ KernelTests/ Core/ Routing/ ContentNegotiationRoutingTest.php - Registers test-specific services.
- DatabaseBackendTagTest::register in core/
tests/ Drupal/ KernelTests/ Core/ Cache/ DatabaseBackendTagTest.php - Registers test-specific services.
- DatabaseStorageExpirableTest::register in core/
tests/ Drupal/ KernelTests/ Core/ KeyValueStore/ DatabaseStorageExpirableTest.php - Registers test-specific services.
26 methods override KernelTestBase::register()
- BaseThemeMissingTest::register in core/
tests/ Drupal/ KernelTests/ Core/ Theme/ BaseThemeMissingTest.php - Registers test-specific services.
- CacheCollectorTest::register in core/
tests/ Drupal/ KernelTests/ Core/ Cache/ CacheCollectorTest.php - Registers test-specific services.
- ContentNegotiationRoutingTest::register in core/
tests/ Drupal/ KernelTests/ Core/ Routing/ ContentNegotiationRoutingTest.php - Registers test-specific services.
- DatabaseBackendTagTest::register in core/
tests/ Drupal/ KernelTests/ Core/ Cache/ DatabaseBackendTagTest.php - Registers test-specific services.
- DatabaseStorageExpirableTest::register in core/
tests/ Drupal/ KernelTests/ Core/ KeyValueStore/ DatabaseStorageExpirableTest.php - Registers test-specific services.
File
-
core/
tests/ Drupal/ KernelTests/ KernelTestBase.php, line 543
Class
- KernelTestBase
- Base class for functional integration tests.
Namespace
Drupal\KernelTestsCode
public function register(ContainerBuilder $container) {
// Keep the container object around for tests.
$this->container = $container;
$container->register('flood', 'Drupal\\Core\\Flood\\MemoryBackend')
->addArgument(new Reference('request_stack'));
$container->register('lock', 'Drupal\\Core\\Lock\\NullLockBackend');
$container->register('cache_factory', 'Drupal\\Core\\Cache\\MemoryBackendFactory');
// Use memory for key value storages to avoid database queries. Store the
// key value factory on the test object so that key value storages persist
// container rebuilds, otherwise all state data would vanish.
if (!isset($this->keyValue)) {
$this->keyValue = new KeyValueMemoryFactory();
}
$container->set('keyvalue', $this->keyValue);
// Set the default language on the minimal container.
$container->setParameter('language.default_values', Language::$defaultValues);
if ($this->strictConfigSchema) {
$container->register('testing.config_schema_checker', ConfigSchemaChecker::class)
->addArgument(new Reference('config.typed'))
->addArgument($this->getConfigSchemaExclusions())
->addTag('event_subscriber');
}
if ($container->hasDefinition('path_alias.path_processor')) {
// The alias-based processor requires the path_alias entity schema to be
// installed, so we prevent it from being registered to the path processor
// manager. We do this by removing the tags that the compiler pass looks
// for. This means that the URL generator can safely be used within tests.
$container->getDefinition('path_alias.path_processor')
->clearTag('path_processor_inbound')
->clearTag('path_processor_outbound');
}
if ($container->hasDefinition('password')) {
$container->getDefinition('password')
->setArguments([
1,
]);
}
// Add the on demand rebuild route provider service.
$route_provider_service_name = 'router.route_provider';
// While $container->get() does a recursive resolve, getDefinition() does
// not, so do it ourselves.
$id = $route_provider_service_name;
while ($container->hasAlias($id)) {
$id = (string) $container->getAlias($id);
}
$definition = $container->getDefinition($id);
$definition->clearTag('needs_destruction');
$container->setDefinition("simpletest.{$route_provider_service_name}", $definition);
$route_provider_definition = new Definition(RouteProvider::class);
$route_provider_definition->setPublic(TRUE);
$container->setDefinition($id, $route_provider_definition);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.