diff --git a/core/modules/simpletest/src/RouteProvider.php b/core/modules/simpletest/src/RouteProvider.php index acff99a..244b98b 100644 --- a/core/modules/simpletest/src/RouteProvider.php +++ b/core/modules/simpletest/src/RouteProvider.php @@ -13,6 +13,8 @@ /** * Rebuilds the router when the provider is instantiated. + * + * @todo Move this outside of simpletest namespace to the Drupal\Tests. */ class RouteProvider implements PreloadableRouteProviderInterface, PagedRouteProviderInterface { diff --git a/core/tests/Drupal/KernelTests/Core/Entity/RouteProviderTest.php b/core/tests/Drupal/KernelTests/Core/Entity/RouteProviderTest.php index 9199c74..c97f03a 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/RouteProviderTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/RouteProviderTest.php @@ -37,13 +37,6 @@ protected function setUp() { $this->installEntitySchema('entity_test_mul'); $this->installEntitySchema('entity_test_admin_routes'); - $router_builder = \Drupal::service('router.builder'); - $router_builder->rebuild(); - - /** @var \Drupal\Core\Routing\RouteBuilderInterface $router_builder */ - $router_builder = \Drupal::service('router.builder'); - $router_builder->rebuild(); - /** @var \Drupal\user\RoleInterface $role */ $role = Role::create([ 'id' => RoleInterface::ANONYMOUS_ID diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index f1a1414..0c056dd 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -25,6 +25,7 @@ use Drupal\simpletest\AssertContentTrait; use Drupal\simpletest\AssertHelperTrait; use Drupal\simpletest\RandomGeneratorTrait; +use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpFoundation\Request; use org\bovigo\vfs\vfsStream; @@ -595,6 +596,16 @@ public function register(ContainerBuilder $container) { $container->getDefinition('password') ->setArguments(array(1)); } + + // While $container->get() does a recursive resolve, getDefinition() does + // not, so do it ourselves. + foreach (['router.route_provider' => 'RouteProvider'] as $original_id => $class) { + for ($id = $original_id; $container->hasAlias($id); $id = (string) $container->getAlias($id)); + $definition = $container->getDefinition($id); + $definition->clearTag('needs_destruction'); + $container->setDefinition("simpletest.$original_id", $definition); + $container->setDefinition($id, new Definition('Drupal\simpletest\\' . $class)); + } } /**