function ServiceProviderTest::register

Same name and namespace in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/ServiceProvider/ServiceProviderTest.php \Drupal\KernelTests\Core\ServiceProvider\ServiceProviderTest::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 KernelTestBase::register

File

core/tests/Drupal/KernelTests/Core/ServiceProvider/ServiceProviderTest.php, line 28

Class

ServiceProviderTest
Tests service provider registration to the DIC.

Namespace

Drupal\KernelTests\Core\ServiceProvider

Code

public function register(ContainerBuilder $container) : void {
  parent::register($container);
  // Undo cache_factory override done in parent because it can hide caching
  // issues in container build time.
  // @see \Drupal\service_provider_test\ServiceProviderTestServiceProvider::alter()
  $this->container
    ->register('cache_factory', CacheFactory::class)
    ->addArgument(new Reference('settings'))
    ->addArgument(new Parameter('cache_default_bin_backends'))
    ->addMethodCall('setContainer', [
    new Reference('service_container'),
  ]);
}

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