class MockRouteProvider
Same name in other branches
- 9 core/modules/system/src/Tests/Routing/MockRouteProvider.php \Drupal\system\Tests\Routing\MockRouteProvider
- 8.9.x core/modules/system/src/Tests/Routing/MockRouteProvider.php \Drupal\system\Tests\Routing\MockRouteProvider
- 10 core/modules/system/src/Tests/Routing/MockRouteProvider.php \Drupal\system\Tests\Routing\MockRouteProvider
Easily configurable mock route provider.
Hierarchy
- class \Drupal\system\Tests\Routing\MockRouteProvider implements \Drupal\Core\Routing\RouteProviderInterface
Expanded class hierarchy of MockRouteProvider
4 files declare their use of MockRouteProvider
- NavigationMenuBlockTest.php in core/
modules/ navigation/ tests/ src/ Kernel/ NavigationMenuBlockTest.php - NavigationMenuMarkupTest.php in core/
modules/ navigation/ tests/ src/ Kernel/ NavigationMenuMarkupTest.php - SystemMenuBlockTest.php in core/
modules/ system/ tests/ src/ Kernel/ Block/ SystemMenuBlockTest.php - SystemMenuNavigationBlockTest.php in core/
modules/ navigation/ tests/ src/ Kernel/ SystemMenuNavigationBlockTest.php
File
-
core/
modules/ system/ src/ Tests/ Routing/ MockRouteProvider.php, line 15
Namespace
Drupal\system\Tests\RoutingView source
class MockRouteProvider implements RouteProviderInterface {
/**
* A collection of routes for this route provider.
*
* @var \Symfony\Component\Routing\RouteCollection
*/
protected $routes;
/**
* Constructs a new MockRouteProvider.
*
* @param \Symfony\Component\Routing\RouteCollection $routes
* The route collection to use for this provider.
*/
public function __construct(RouteCollection $routes) {
$this->routes = $routes;
}
/**
* Implements \Drupal\Core\Routing\RouteProviderInterface::getRouteCollectionForRequest().
*
* Simply return all routes to prevent
* \Symfony\Component\Routing\Exception\ResourceNotFoundException.
*/
public function getRouteCollectionForRequest(Request $request) {
return $this->routes;
}
/**
* {@inheritdoc}
*/
public function getRouteByName($name) {
$routes = $this->getRoutesByNames([
$name,
]);
if (empty($routes)) {
throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
}
return reset($routes);
}
/**
* {@inheritdoc}
*/
public function preLoadRoutes($names) {
// Nothing to do.
}
/**
* {@inheritdoc}
*/
public function getRoutesByNames($names) {
$routes = [];
foreach ($names as $name) {
$routes[] = $this->routes
->get($name);
}
return $routes;
}
/**
* {@inheritdoc}
*/
public function getRoutesByPattern($pattern) {
return new RouteCollection();
}
/**
* {@inheritdoc}
*/
public function getAllRoutes() {
return $this->routes
->all();
}
/**
* {@inheritdoc}
*/
public function reset() {
$this->routes = [];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
MockRouteProvider::$routes | protected | property | A collection of routes for this route provider. | |
MockRouteProvider::getAllRoutes | public | function | Returns all the routes on the system. | Overrides RouteProviderInterface::getAllRoutes |
MockRouteProvider::getRouteByName | public | function | Find the route using the provided route name. | Overrides RouteProviderInterface::getRouteByName |
MockRouteProvider::getRouteCollectionForRequest | public | function | Implements \Drupal\Core\Routing\RouteProviderInterface::getRouteCollectionForRequest(). | Overrides RouteProviderInterface::getRouteCollectionForRequest |
MockRouteProvider::getRoutesByNames | public | function | Find many routes by their names using the provided list of names. | Overrides RouteProviderInterface::getRoutesByNames |
MockRouteProvider::getRoutesByPattern | public | function | Get all routes which match a certain pattern. | Overrides RouteProviderInterface::getRoutesByPattern |
MockRouteProvider::preLoadRoutes | public | function | ||
MockRouteProvider::reset | public | function | Resets the route provider object. | Overrides RouteProviderInterface::reset |
MockRouteProvider::__construct | public | function | Constructs a new MockRouteProvider. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.