function RouteBuilderTest::testRebuildWithOverriddenRouteClass

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php \Drupal\Tests\Core\Routing\RouteBuilderTest::testRebuildWithOverriddenRouteClass()
  2. 8.9.x core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php \Drupal\Tests\Core\Routing\RouteBuilderTest::testRebuildWithOverriddenRouteClass()
  3. 11.x core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php \Drupal\Tests\Core\Routing\RouteBuilderTest::testRebuildWithOverriddenRouteClass()

Tests routes can use alternative compiler classes.

See also

\Drupal\Core\Routing\RouteBuilder::rebuild()

File

core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php, line 285

Class

RouteBuilderTest
@coversDefaultClass \Drupal\Core\Routing\RouteBuilder @group Routing

Namespace

Drupal\Tests\Core\Routing

Code

public function testRebuildWithOverriddenRouteClass() : void {
    $this->lock
        ->expects($this->once())
        ->method('acquire')
        ->with('router_rebuild')
        ->willReturn(TRUE);
    $this->yamlDiscovery
        ->expects($this->once())
        ->method('findAll')
        ->willReturn([
        'test_module' => [
            'test_route.override' => [
                'path' => '/test_route_override',
                'options' => [
                    'compiler_class' => 'Class\\Does\\Not\\Exist',
                ],
            ],
            'test_route' => [
                'path' => '/test_route',
            ],
        ],
    ]);
    $container = new ContainerBuilder();
    $container->set('test_module.route_service', new TestRouteSubscriber());
    // Test that routes can have alternative compiler classes.
    $route_collection_filled = new RouteCollection();
    $route_collection_filled->add('test_route.override', new Route('/test_route_override', [], [], [
        'compiler_class' => 'Class\\Does\\Not\\Exist',
    ]));
    $route_collection_filled->add('test_route', new Route('/test_route', [], [], [
        'compiler_class' => RouteCompiler::class,
    ]));
    $route_build_event = new RouteBuildEvent($route_collection_filled);
    $this->dispatcher
        ->dispatch($route_build_event, RoutingEvents::DYNAMIC)
        ->shouldBeCalled();
    $this->dispatcher
        ->dispatch($route_build_event, RoutingEvents::ALTER)
        ->shouldBeCalled();
    $this->assertTrue($this->routeBuilder
        ->rebuild());
}

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