MockRouteProvider.php in Zircon Profile 8
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(array(
$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 = array();
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 = array();
}
}