public function test_invoke()
 {
     $invoker = new ArraySyntaxRouteInvoker();
     $container = new Container();
     $item = new FooItem();
     $route = new Route([HttpRequestMethod::GET], 'foo', [FooItem::class, 'test']);
     $route->setParameter('bar', $item);
     $this->assertTrue($invoker->invoke($route, $container) === $item);
 }
 public function test_invoke()
 {
     $invoker = new CallableRouteInvoker();
     $item = new FooItem();
     $route = new Route([HttpRequestMethod::GET], 'foo', function (FooItem $foo, FooItem $item) {
         return $item;
     });
     $route->setParameter('item', $item);
     $this->assertTrue($invoker->invoke($route, new Container()) === $item);
 }
Ejemplo n.º 3
0
 public function test_build_response_for_mapping_with_custom_response()
 {
     $builder = new ResponseBuilder();
     $route = new Route([HttpRequestMethod::GET], 'foo', 'bar');
     $routeResponse = new HttpResponse(HttpStatusCode::NOT_FOUND, 'Yada yada', new HttpHeaders(['foo' => 'bar', 'bar' => 'foo']));
     $route->setAction($routeResponse);
     $response = $builder->buildResponseForRoute($route);
     $this->assertEquals($routeResponse->getStatusCode(), $response->getStatusCode());
     $this->assertEquals($routeResponse->getHeaders()->get('foo'), $response->getHeaders()->get('foo'));
     $this->assertEquals($routeResponse->getHeaders()->get('bar'), $response->getHeaders()->get('bar'));
 }
Ejemplo n.º 4
0
 public function test_get_and_set_parameters()
 {
     $route = new Route([HttpRequestMethod::GET], '/', 'foo');
     $route->setParameters(['foo' => 'bar', 'baz' => null]);
     $this->assertEquals('bar', $route->getParameter('foo'));
     $this->assertEquals('bar', $route->getParameter('baz', 'bar'));
     $this->assertEquals('swag', $route->getParameter('yolo', 'swag'));
     $route->setParameter('yolo', 'swag');
     $this->assertEquals('swag', $route->getParameter('yolo'));
 }