/** * @inheritDoc */ public function toRoute(string $routeName, array $variables = [], array $query = []) : UriInterface { $route = $this->routes->findByName($routeName); if ($route === null) { throw new RouteNotFoundException(sprintf('Unable to generate an URL for the named route "%s" as such route does not exist.', $routeName)); } return $this->buildRouteUri($route, $variables, $query); }
function it_generates_url_to_named_route(RouteCollection $routeCollection, Route $route, UriInterface $uri) { $routeCollection->findByName('name')->willReturn($route); $route->getScheme()->willReturn('http'); $route->getHost()->willReturn('example.com'); $route->compilePath(['key' => 'value'])->willReturn('/url'); $uri->withScheme('http')->willReturn($uri); $uri->withHost('example.com')->willReturn($uri); $uri->withPath('/url')->willReturn($uri); $uri->withQuery('param=val')->willReturn($uri); $result = $this->toRoute('name', ['key' => 'value'], ['param' => 'val']); $result->shouldBe($uri); $uri->withScheme('http')->shouldHaveBeenCalled(); $uri->withHost('example.com')->shouldHaveBeenCalled(); $uri->withPath('/url')->shouldHaveBeenCalled(); }
/** * @inheritDoc */ public function findByName(string $routeName) { return $this->routes->findByName($routeName); }