function LazyRouteCollectionTest::testGetName

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Routing/LazyRouteCollectionTest.php \Drupal\Tests\Core\Routing\LazyRouteCollectionTest::testGetName()
  2. 10 core/tests/Drupal/Tests/Core/Routing/LazyRouteCollectionTest.php \Drupal\Tests\Core\Routing\LazyRouteCollectionTest::testGetName()

Search for a both an existing and a non-existing route.

@covers ::get

File

core/tests/Drupal/Tests/Core/Routing/LazyRouteCollectionTest.php, line 77

Class

LazyRouteCollectionTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Routing%21LazyRouteCollection.php/class/LazyRouteCollection/11.x" title="LazyRouteCollection" class="local">\Drupal\Core\Routing\LazyRouteCollection</a>

Namespace

Drupal\Tests\Core\Routing

Code

public function testGetName() : void {
    // Hit.
    $this->routeProvider
        ->method('getRouteByName')
        ->with('route_1')
        ->willReturn($this->testRoutes['route_1']);
    $lazyRouteCollection = new LazyRouteCollection($this->routeProvider);
    $this->assertEquals($lazyRouteCollection->get('route_1'), $this->testRoutes['route_1']);
    // Miss.
    $this->routeProvider
        ->method('getRouteByName')
        ->with('does_not_exist')
        ->will($this->throwException(new RouteNotFoundException()));
    $lazyRouteCollectionFail = new LazyRouteCollection($this->routeProvider);
    $this->assertNull($lazyRouteCollectionFail->get('does_not_exist'));
}

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