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]); }
/** * @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."); } }
public function addRoute(Route $route, \Closure $controllerClosure) { $this->slimApp->map([$route->httpVerb()], $route->pathExpression(), $controllerClosure)->setName($route->name()); }