function it_can_throw_an_exception_if_the_controller_isnt_in_the_container(ControllerClosureBuilder $controllerClosureBuilder, SlimAppAdapter $slimAppAdapter, Route $route, ContainerInterface $container, ErrorController $errorController)
 {
     // ARRANGE
     // Route has stuff on it
     $route->controllerServiceId()->willReturn('controller-service-id');
     $route->name()->willReturn('route-name');
     // Controller is not in container
     $container->has('controller-service-id')->willReturn(false);
     // ACT/ASSERT
     $this->shouldThrow('\\Sainsburys\\HttpService\\Components\\Routing\\Exception\\InvalidRouteConfigException')->during('configureApplicationWithRoutes', [$slimAppAdapter, [$route], $container, $errorController]);
 }
 public function buildControllerClosure(ContainerInterface $container, Route $route) : \Closure
 {
     $controllerServiceId = $route->controllerServiceId();
     $actionMethodName = $route->actionMethodName();
     $controllerClosure = function (ServerRequestInterface $request, ResponseInterface $response) use($container, $controllerServiceId, $actionMethodName) {
         $controllerObject = $container->get($controllerServiceId);
         $controllerResponse = $controllerObject->{$actionMethodName}($request, $response);
         return $controllerResponse;
     };
     return $controllerClosure;
 }
 function it_can_build_a_controller_closure(ContainerInterface $container, Route $route, SimpleController $simpleController, ServerRequestInterface $request, ResponseInterface $response, JsonResponse $jsonResponse)
 {
     // ARRANGE
     $route->controllerServiceId()->willReturn('controller-service-id');
     $route->actionMethodName()->willReturn('simpleAction');
     $container->get('controller-service-id')->willReturn($simpleController);
     $simpleController->simpleAction($request, $response)->willReturn($jsonResponse);
     // ACT
     $controllerClosure = $this->buildControllerClosure($container, $route);
     $result = $controllerClosure($request, $response);
     // ASSERT
     $controllerClosure->shouldHaveType('closure');
     $result->shouldBe($jsonResponse);
 }
 /**
  * @throws InvalidRouteConfigException
  */
 private function validateControllerIsInDiConfig(Route $route, ContainerInterface $container)
 {
     if (!$container->has($route->controllerServiceId())) {
         throw new InvalidRouteConfigException("Route " . $route->name() . "' requires controller service ID '" . $route->controllerServiceId() . "' - not found in DI config.");
     }
 }