class RouteMatchTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/Core/Routing/RouteMatchTest.php \Drupal\Tests\Core\Routing\RouteMatchTest
- 10 core/tests/Drupal/Tests/Core/Routing/RouteMatchTest.php \Drupal\Tests\Core\Routing\RouteMatchTest
- 9 core/tests/Drupal/Tests/Core/Routing/RouteMatchTest.php \Drupal\Tests\Core\Routing\RouteMatchTest
- 8.9.x core/tests/Drupal/Tests/Core/Routing/RouteMatchTest.php \Drupal\Tests\Core\Routing\RouteMatchTest
Tests Drupal\Core\Routing\RouteMatch.
Attributes
#[CoversClass(RouteMatch::class)]
#[Group('Routing')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\Core\Routing\RouteMatchTestBase extends \Drupal\Tests\UnitTestCase
- class \Drupal\Tests\Core\Routing\RouteMatchTest extends \Drupal\Tests\Core\Routing\RouteMatchTestBase
- class \Drupal\Tests\Core\Routing\RouteMatchTestBase extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of RouteMatchTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Routing/ RouteMatchTest.php, line 19
Namespace
Drupal\Tests\Core\RoutingView source
class RouteMatchTest extends RouteMatchTestBase {
/**
* {@inheritdoc}
*/
protected static function getRouteMatch(string $name, Route $route, array $parameters, array $raw_parameters) : RouteMatchInterface {
return new RouteMatch($name, $route, $parameters, $raw_parameters);
}
/**
* Tests route match from request.
*
* @legacy-covers ::createFromRequest
* @legacy-covers ::__construct
*/
public function testRouteMatchFromRequest() : void {
$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
| Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title |
|---|---|---|---|---|---|
| DrupalTestCaseTrait::checkErrorHandlerOnTearDown | public | function | Checks the test error handler after test execution. | ||
| ExpectDeprecationTrait::expectDeprecation | Deprecated | public | function | Adds an expected deprecation. | |
| ExpectDeprecationTrait::regularExpressionForFormatDescription | private | function | |||
| RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | ||
| RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | ||
| RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | ||
| RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | ||
| RouteMatchTest::getRouteMatch | protected static | function | Build a test route match object for the given implementation. | Overrides RouteMatchTestBase::getRouteMatch | |
| RouteMatchTest::testRouteMatchFromRequest | public | function | Tests route match from request. | ||
| RouteMatchTestBase::routeMatchProvider | public static | function | Provide sets of parameters and expected parameters for parameter tests. | ||
| RouteMatchTestBase::testGetParameter | public | function | Tests get parameter. | ||
| RouteMatchTestBase::testGetParameters | public | function | Tests get parameters. | ||
| RouteMatchTestBase::testGetRawParameter | public | function | Tests get raw parameter. | ||
| RouteMatchTestBase::testGetRawParameters | public | function | Tests get raw parameters. | ||
| RouteMatchTestBase::testGetRouteName | public | function | Tests get route name. | ||
| RouteMatchTestBase::testGetRouteObject | public | function | Tests get route object. | ||
| UnitTestCase::$root | protected | property | The app root. | ||
| 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::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | ||
| UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | ||
| UnitTestCase::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | ||
| UnitTestCase::setUp | protected | function | |||
| UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.