public function testRoutesWithConditions()
 {
     $routes = new RouteCollection();
     $routes->add('foo', new Route('/foo', array(), array(), array(), 'baz', array(), array(), "request.headers.get('User-Agent') matches '/firefox/i'"));
     $context = new RequestContext();
     $context->setHost('baz');
     $matcher = new TraceableUrlMatcher($routes, $context);
     $notMatchingRequest = Request::create('/foo', 'GET');
     $traces = $matcher->getTracesForRequest($notMatchingRequest);
     $this->assertEquals("Condition \"request.headers.get('User-Agent') matches '/firefox/i'\" does not evaluate to \"true\"", $traces[0]['log']);
     $matchingRequest = Request::create('/foo', 'GET', array(), array(), array(), array('HTTP_USER_AGENT' => 'Firefox'));
     $traces = $matcher->getTracesForRequest($matchingRequest);
     $this->assertEquals('Route matches!', $traces[0]['log']);
 }
Пример #2
0
 /**
  * Returns the routing traces associated to the given request.
  *
  * @param RequestDataCollector $request
  * @param string               $method
  *
  * @return array
  */
 private function getTraces(RequestDataCollector $request, $method)
 {
     $traceRequest = Request::create($request->getPathInfo(), $request->getRequestServer()->get('REQUEST_METHOD'), $request->getRequestAttributes()->all(), $request->getRequestCookies()->all(), array(), $request->getRequestServer()->all());
     $context = $this->matcher->getContext();
     $context->setMethod($method);
     $matcher = new TraceableUrlMatcher($this->routes, $context);
     return $matcher->getTracesForRequest($traceRequest);
 }