/** * @inheritDoc */ public function toCurrent(array $variables = [], array $query = []) : UriInterface { $route = $this->request->getRoute(); if ($route === null) { throw new RouteNotFoundException(sprintf('Unable to generate an URL for current.')); } return $this->buildRouteUri($route, $variables, $query); }
function it_generates_url_to_current_route(Request $request, Route $route, UriInterface $uri) { $request->getRoute()->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->toCurrent(['key' => 'value'], ['param' => 'val']); $result->shouldBe($uri); $uri->withScheme('http')->shouldHaveBeenCalled(); $uri->withHost('example.com')->shouldHaveBeenCalled(); $uri->withPath('/url')->shouldHaveBeenCalled(); }