Exemple #1
0
 public function testBuilder()
 {
     // given
     $routeMap = new RouteMap();
     $req = new Request();
     $req->setUrl('/foo/123');
     $req->setHttpMethod(Http::METHOD_GET);
     $req->setProtocol(Http::HTTPS);
     // when
     $routeMap->connect('test', RouteBuilder::get()->uri('/foo/:id')->method(Http::METHOD_GET)->command('Fliglio\\Routing.StubResource.getFlub')->protocol(Http::HTTPS)->param('bar', 'baz')->build())->connect(null, RouteBuilder::get()->key('test2')->uri('/foo2/:id')->method(Http::METHOD_GET)->command('Fliglio\\Routing.StubResource.getFlub2')->protocol(Http::HTTPS)->param('bar', 'baz')->build())->connectRoute(RouteBuilder::get()->key('test3')->uri('/foo3/:id')->method(Http::METHOD_GET)->command('Fliglio\\Routing.StubResource.getFlub3')->protocol(Http::HTTPS)->param('bar', 'baz')->build());
     // then
     $route = $routeMap->getRoute($req);
     $params = $route->getParams();
     $this->assertEquals($params, array('id' => 123, 'bar' => 'baz'));
     $this->assertEquals('Fliglio\\Routing\\StubResource', get_class($route->getResourceInstance()));
     $this->assertEquals('getFlub', $route->getResourceMethod());
     // and
     $req->setUrl('/foo2/123');
     $route = $routeMap->getRoute($req);
     $this->assertEquals('getFlub2', $route->getResourceMethod());
     // and
     $req->setUrl('/foo3/123');
     $route = $routeMap->getRoute($req);
     $this->assertEquals('getFlub3', $route->getResourceMethod());
 }
Exemple #2
0
 public function createContext($url)
 {
     $request = new Request();
     $request->setProtocol(Http::HTTP);
     $request->setHttpMethod(Http::METHOD_GET);
     $request->setUrl($url);
     $context = new Context($request, new Response());
     return $context;
 }
Exemple #3
0
 public function createDefault()
 {
     $inst = new Request();
     $inst->setProtocol(self::getProtocol());
     $inst->setHost(self::getHost());
     $inst->setUrl(self::getCurrentUrl());
     $inst->setHttpMethod(self::getHttpMethod());
     $inst->setBody(self::getBody());
     $inst->setGetParams(self::getGetParams());
     $headers = self::getRequestHeaders();
     foreach ($headers as $key => $val) {
         $inst->addHeader($key, $val);
     }
     return $inst;
 }