MockRouteProvider.php in Drupal 10
File
core/modules/system/src/Tests/Routing/MockRouteProvider.php
View source
<?php
namespace Drupal\system\Tests\Routing;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Routing\RouteCollection;
use Drupal\Core\Routing\RouteProviderInterface;
class MockRouteProvider implements RouteProviderInterface {
protected $routes;
public function __construct(RouteCollection $routes) {
$this->routes = $routes;
}
public function getRouteCollectionForRequest(Request $request) {
return $this->routes;
}
public function getRouteByName($name) {
$routes = $this
->getRoutesByNames([
$name,
]);
if (empty($routes)) {
throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
}
return reset($routes);
}
public function preLoadRoutes($names) {
}
public function getRoutesByNames($names) {
$routes = [];
foreach ($names as $name) {
$routes[] = $this->routes
->get($name);
}
return $routes;
}
public function getRoutesByPattern($pattern) {
return new RouteCollection();
}
public function getAllRoutes() {
return $this->routes
->all();
}
public function reset() {
$this->routes = [];
}
}