function it_dispatches_with_declared_action(ControllerFactoryInterface $factory, Context $context, ControllerInterface $controller, Response $response) { $request = Request::create('/', 'OPTIONS'); $context->getHandler()->willReturn('test'); $context->getVariables()->willReturn(['foo']); $factory->build('test')->willReturn($controller); $controller->options($request, ['foo'])->willReturn($response); $this->dispatch($request, $context)->shouldReturn($response); }
public function dispatch(Request $request, Context $context) { $handler = $context->getHandler(); list($handler, $action) = $this->extractComponents($handler, $request); $controller = $this->getFactory()->build($handler); $variables = $context->getVariables(); $method = $request->getMethod(); if (!method_exists($controller, $method)) { throw new BadMethodCallException("Method {$method} not found on handler {$handler}"); } return call_user_func([$controller, strtolower($method)], $request, $variables); }