function RouteBuilderTest::testRebuildIfNeeded

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

Tests \Drupal\Core\Routing\RouteBuilder::rebuildIfNeeded() method.

File

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

Class

RouteBuilderTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Routing%21RouteBuilder.php/class/RouteBuilder/11.x" title="Managing class for rebuilding the router table." class="local">\Drupal\Core\Routing\RouteBuilder</a> @group Routing

Namespace

Drupal\Tests\Core\Routing

Code

public function testRebuildIfNeeded() : void {
    $this->lock
        ->expects($this->once())
        ->method('acquire')
        ->with('router_rebuild')
        ->willReturn(TRUE);
    $this->lock
        ->expects($this->once())
        ->method('release')
        ->with('router_rebuild');
    $this->yamlDiscovery
        ->expects($this->any())
        ->method('findAll')
        ->willReturn([]);
    $this->routeBuilder
        ->setRebuildNeeded();
    // This will trigger a successful rebuild.
    $this->assertTrue($this->routeBuilder
        ->rebuildIfNeeded());
    // This will not trigger a rebuild.
    $this->assertFalse($this->routeBuilder
        ->rebuildIfNeeded());
}

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