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. 11.x 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 \Drupal\Core\Routing\LazyRouteCollection[[api-linebreak]]

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.