/** * context must be propagated also when routers are added after context is set */ public function testContextOrder() { list($low, $high) = $this->createRouterMocks(); $low->expects($this->once())->method('setContext')->with($this->context); $high->expects($this->once())->method('setContext')->with($this->context); $this->router->setContext($this->context); $this->router->add($low, 10); $this->router->add($high, 100); $this->router->all(); $this->assertSame($this->context, $this->router->getContext()); }
/** * @throws ResourceNotFoundException If no match was found */ public function parse($url) { // we create a request with a new context in order to match $url to a route and get its properties $request = Request::create($url, "GET"); $originalContext = $this->router->getContext(); $context = clone $originalContext; $context->fromRequest($request); $this->router->setContext($context); try { $matchResult = $this->router->matchRequest($request); } catch (ResourceNotFoundException $e) { $this->router->setContext($originalContext); throw new InvalidArgumentException("No route matched '{$url}'"); } if (!$this->matchesRestRequest($matchResult)) { $this->router->setContext($originalContext); throw new InvalidArgumentException("No route matched '{$url}'"); } $this->router->setContext($originalContext); return $matchResult; }
/** * Call match on ChainRouter that has RequestMatcher in the chain. * * @dataProvider provideBaseUrl */ public function testMatchWithRequestMatchersAndContext($baseUrl) { $url = '//test'; list($low) = $this->createRouterMocks(); $high = $this->getMock('Symfony\\Cmf\\Component\\Routing\\Tests\\Routing\\RequestMatcher'); $high->expects($this->once())->method('matchRequest')->with($this->callback(function (Request $r) use($url, $baseUrl) { return true === $r->isSecure() && 'foobar.com' === $r->getHost() && 4433 === $r->getPort() && $baseUrl === $r->getBaseUrl() && $url === $r->getPathInfo(); }))->will($this->throwException(new \Symfony\Component\Routing\Exception\ResourceNotFoundException())); $low->expects($this->once())->method('match')->with($url)->will($this->returnValue(array('test'))); $this->router->add($low, 10); $this->router->add($high, 20); $requestContext = new RequestContext(); $requestContext->setScheme('https'); $requestContext->setHost('foobar.com'); $requestContext->setHttpsPort(4433); $requestContext->setBaseUrl($baseUrl); $this->router->setContext($requestContext); $result = $this->router->match($url); $this->assertEquals(array('test'), $result); }
/** * {@inheritdoc} */ public function setContext(SymfonyRequestContext $context) { $this->chainRouter->setContext($context); }