Example #1
0
 private function createContext(Url $url)
 {
     $request = new Request();
     $request->setHttpMethod(Http::METHOD_GET);
     $request->setUrl($url);
     return new Context($request, new Response());
 }
Example #2
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());
 }
Example #3
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;
 }
Example #4
0
 /**
  * @expectedException \Exception
  */
 public function testMuxNoRoutingKey()
 {
     // given
     $coll = new Collective($this->driver, $this->mapper, $this->routing);
     $coll->assimilate($this);
     $args = ["hello world", new Chan(null, $this->driver, $this->mapper), new Foo("bar")];
     $req2 = $this->buildRequest($args);
     $req = new Request();
     $req->setBody($req2->getBody());
     // when
     $resp = $coll->mux($req);
 }
Example #5
0
 public function marshalRoutineRequest(RoutineRequest $req)
 {
     $type = $req->getType();
     $method = $req->getMethod();
     $vos = $this->marshalForMethod($req->getArgs(), $req->getType(), $req->getMethod());
     $vos[] = $this->marshalArg($req->getExitChan(), Chan::CLASSNAME);
     $vos[] = $req->getRetryErrors();
     $topicStr = $this->marshalTopicString($req->getNs(), $req->getDc(), $req->getType(), $req->getMethod());
     $r = new Request();
     $r->addHeader('X-routing-key', $topicStr);
     $r->setBody(json_encode($vos));
     return $r;
 }
Example #6
0
 public function testTopicFromString()
 {
     // given
     $x = $this->buildRequest('', '', 'Fliglio\\Borg\\TopicTest', 'testTopic');
     $x2 = $this->mapper->marshalRoutineRequest($x);
     $req = new Request();
     $req->addHeader("X-routing-key", 'foo.bar.Fliglio.Borg.TopicTest.testTopic');
     $req->setBody($x2->getBody());
     // when
     $found = $this->mapper->unmarshalRoutineRequest($req);
     // then
     $this->assertEquals('foo', $found->getNs(), 'should match');
     $this->assertEquals('bar', $found->getDc(), 'should match');
     $this->assertEquals('Fliglio\\Borg\\TopicTest', $found->getType(), 'should match');
     $this->assertEquals('testTopic', $found->getMethod(), 'should match');
 }
Example #7
0
 public function testHeaderParsing()
 {
     // given
     $req = new Request();
     $req->addHeader('created', '2010-10-10');
     $req->addHeader('expiration', '2010-10-11');
     $req->addHeader('custom-header', 'foo');
     $ctx = new Context($req, new Response());
     $injectable = new MessageInjectableFactory();
     // when
     $msg = $injectable->create($ctx, '');
     // then
     $this->assertEquals($msg->getCreated(), '2010-10-10');
     $this->assertEquals($msg->getExpiration(), '2010-10-11');
     $this->assertEquals($msg->getHeader('custom-header'), 'foo');
 }
Example #8
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;
 }