/** * Sets the router that should be used to handle routing and request resolution duties. * * @param Router $router */ public function setRouter(Router $router) { $this->router = $router; $this->router->setContext($this->context); $this->context->registerInstance($router); }
public function testCreateRedirect() { // Prepare: Prepare environment to capture response $response = new Response(); $request = new Request(); $request->setRequestUri('/redirect/bla'); $context = new Context(); $context->registerInstance($response); $context->registerInstance($request); $router = new Router(); $router->setContext($context); $route = $router->createRedirect('/redirect/$testVar', '/target/$testVar', true); $this->assertEquals('/redirect/$testVar', $route->getPattern()); $routeResult = $router->route($request); $this->assertEquals($route, $routeResult); $router->dispatch($routeResult, $request); $this->assertEquals(ResponseCode::HTTP_MOVED_PERMANENTLY, $response->getResponseCode()); $this->assertEquals('/target/bla', $response->getHeader('Location')); }