You are here

class RouteMatchTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Routing/RouteMatchTest.php \Drupal\Tests\Core\Routing\RouteMatchTest
  2. 9 core/tests/Drupal/Tests/Core/Routing/RouteMatchTest.php \Drupal\Tests\Core\Routing\RouteMatchTest

@coversDefaultClass \Drupal\Core\Routing\RouteMatch @group Routing

Hierarchy

Expanded class hierarchy of RouteMatchTest

File

core/tests/Drupal/Tests/Core/Routing/RouteMatchTest.php, line 15

Namespace

Drupal\Tests\Core\Routing
View source
class RouteMatchTest extends RouteMatchTestBase {

  /**
   * {@inheritdoc}
   */
  protected function getRouteMatch($name, Route $route, array $parameters, array $raw_parameters) {
    return new RouteMatch($name, $route, $parameters, $raw_parameters);
  }

  /**
   * @covers ::createFromRequest
   * @covers ::__construct
   */
  public function testRouteMatchFromRequest() {
    $request = new Request();

    // A request that hasn't been routed yet.
    $route_match = RouteMatch::createFromRequest($request);
    $this
      ->assertNull($route_match
      ->getRouteName());
    $this
      ->assertNull($route_match
      ->getRouteObject());
    $this
      ->assertSame([], $route_match
      ->getParameters()
      ->all());
    $this
      ->assertNull($route_match
      ->getParameter('foo'));
    $this
      ->assertSame([], $route_match
      ->getRawParameters()
      ->all());
    $this
      ->assertNull($route_match
      ->getRawParameter('foo'));

    // A routed request without parameter upcasting.
    $route = new Route('/test-route/{foo}');
    $request->attributes
      ->set(RouteObjectInterface::ROUTE_NAME, 'test_route');
    $request->attributes
      ->set(RouteObjectInterface::ROUTE_OBJECT, $route);
    $request->attributes
      ->set('foo', '1');
    $route_match = RouteMatch::createFromRequest($request);
    $this
      ->assertSame('test_route', $route_match
      ->getRouteName());
    $this
      ->assertSame($route, $route_match
      ->getRouteObject());
    $this
      ->assertSame([
      'foo' => '1',
    ], $route_match
      ->getParameters()
      ->all());
    $this
      ->assertSame([], $route_match
      ->getRawParameters()
      ->all());

    // A routed request with parameter upcasting.
    $foo = new \stdClass();
    $foo->value = 1;
    $request->attributes
      ->set('foo', $foo);
    $request->attributes
      ->set('_raw_variables', new InputBag([
      'foo' => '1',
    ]));
    $route_match = RouteMatch::createFromRequest($request);
    $this
      ->assertSame([
      'foo' => $foo,
    ], $route_match
      ->getParameters()
      ->all());
    $this
      ->assertSame([
      'foo' => '1',
    ], $route_match
      ->getRawParameters()
      ->all());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
RouteMatchTest::getRouteMatch protected function Build a test route match object for the given implementation. Overrides RouteMatchTestBase::getRouteMatch
RouteMatchTest::testRouteMatchFromRequest public function @covers ::createFromRequest @covers ::__construct
RouteMatchTestBase::routeMatchProvider public function Provide sets of parameters and expected parameters for parameter tests.
RouteMatchTestBase::testGetParameter public function @covers ::getParameter @covers \Drupal\Core\Routing\RouteMatch::getParameterNames @dataProvider routeMatchProvider
RouteMatchTestBase::testGetParameters public function @covers ::getParameters @covers \Drupal\Core\Routing\RouteMatch::getParameterNames @dataProvider routeMatchProvider
RouteMatchTestBase::testGetRawParameter public function @covers ::getRawParameter @covers \Drupal\Core\Routing\RouteMatch::getParameterNames @dataProvider routeMatchProvider
RouteMatchTestBase::testGetRawParameters public function @covers ::getRawParameters @covers \Drupal\Core\Routing\RouteMatch::getParameterNames @dataProvider routeMatchProvider
RouteMatchTestBase::testGetRouteName public function @covers ::getRouteName @dataProvider routeMatchProvider
RouteMatchTestBase::testGetRouteObject public function @covers ::getRouteObject @dataProvider routeMatchProvider
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 206
UnitTestCase::setUpBeforeClass public static function