You are here

public static function TestServiceProvider::addRouteProvider in Drupal 8

Add the on demand rebuild route provider service.

Parameters

\Drupal\Core\DependencyInjection\ContainerBuilder $container:

2 calls to TestServiceProvider::addRouteProvider()
KernelTestBase::register in core/tests/Drupal/KernelTests/KernelTestBase.php
Registers test-specific services.
TestServiceProvider::alter in core/tests/Drupal/KernelTests/TestServiceProvider.php
Modifies existing service definitions.

File

core/tests/Drupal/KernelTests/TestServiceProvider.php, line 43

Class

TestServiceProvider
Provides special routing services for tests.

Namespace

Drupal\KernelTests

Code

public static function addRouteProvider(ContainerBuilder $container) {
  $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);
  $container
    ->setDefinition($id, new Definition(RouteProvider::class));
}