function RouterTest::testMatchRequest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Routing/RouterTest.php \Drupal\KernelTests\Core\Routing\RouterTest::testMatchRequest()

Tests the router request matching.

File

core/tests/Drupal/KernelTests/Core/Routing/RouterTest.php, line 54

Class

RouterTest
Tests the router.

Namespace

Drupal\KernelTests\Core\Routing

Code

public function testMatchRequest() : void {
  $defaults = $this->router
    ->match('/admin');
  $this->assertIsArray($defaults);
  $this->assertArrayHasKey('_route', $defaults);
  $this->assertEquals('system.admin', $defaults['_route']);
  try {
    $this->router
      ->match('/does/not/exist');
    $this->fail(sprintf('%s::match() should throw an exception for a non-existing path.', Router::class));
  } catch (CacheableResourceNotFoundException $exception) {
    $this->assertEquals([], $exception->getCacheContexts());
    $this->assertEquals([], $exception->getCacheTags());
    $this->assertEquals(Cache::PERMANENT, $exception->getCacheMaxAge());
  } catch (\Throwable $exception) {
    $this->fail(sprintf('%s::match() should throw %s, %s thrown instead.', Router::class, CacheableResourceNotFoundException::class, get_class($exception)));
  }
}

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