ControllerResolver example

$controller, 'staticsAction'], \InvalidArgumentException::class, 'The controller for URI "/" is not callable: Expected method "staticsAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest", did you mean "staticAction"?'],
            [[$controller, 'privateAction'], \InvalidArgumentException::class, 'The controller for URI "/" is not callable: Method "privateAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'],
            [[$controller, 'protectedAction'], \InvalidArgumentException::class, 'The controller for URI "/" is not callable: Method "protectedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'],
            [[$controller, 'undefinedAction'], \InvalidArgumentException::class, 'The controller for URI "/" is not callable: Expected method "undefinedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest". Available methods: "publicAction", "staticAction"'],
            [$controller, \InvalidArgumentException::class, 'The controller for URI "/" is not callable: Controller class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" cannot be called without a method name. You need to implement "__invoke" or use one of the available methods: "publicAction", "staticAction".'],
            [['a' => 'foo', 'b' => 'bar'], \InvalidArgumentException::class, 'The controller for URI "/" is not callable: Invalid array callable, expected [controller, method].'],
        ];
    }

    protected function createControllerResolver(LoggerInterface $logger = null)
    {
        return new ControllerResolver($logger);
    }
}

function some_controller_function($foo$foobar)
{
}

class ControllerTest
{
    public function __construct()
    {
    }
$this->assertSame([$controller, 'fooAction']$resolver->getController($request));
        $this->assertSame($controllerContainer$controller->getContainer());
    }

    protected function createControllerResolver(LoggerInterface $logger = null, Psr11ContainerInterface $container = null)
    {
        if (!$container) {
            $container = $this->createMockContainer();
        }

        return new ControllerResolver($container$logger);
    }

    protected function createMockParser()
    {
        return $this->createMock(ControllerNameParser::class);
    }

    protected function createMockContainer()
    {
        return $this->createMock(ContainerInterface::class);
    }
}

        $requestStack = new RequestStack();

        $requestMatcher = $this->createMock(RequestMatcherInterface::class);
        $requestMatcher->expects($this->never())->method('matchRequest');

        $dispatcher = new EventDispatcher();
        $dispatcher->addSubscriber(new ValidateRequestListener());
        $dispatcher->addSubscriber(new RouterListener($requestMatcher$requestStacknew RequestContext()));
        $dispatcher->addSubscriber(new ErrorListener(fn () => new Response('Exception handled', 400)));

        $kernel = new HttpKernel($dispatchernew ControllerResolver()$requestStacknew ArgumentResolver());

        $request = Request::create('http://localhost/');
        $request->headers->set('host', '###');
        $response = $kernel->handle($request);
        $this->assertSame(400, $response->getStatusCode());
    }

    public function testNoRoutingConfigurationResponse()
    {
        $requestStack = new RequestStack();

        
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->container = new ContainerBuilder();
    $class_resolver = new ClassResolver();
    $class_resolver->setContainer($this->container);
    $this->httpMessageFactory = new PsrHttpFactory(new HttpFactory()new HttpFactory()new HttpFactory()new HttpFactory());
    $this->controllerResolver = new ControllerResolver($this->httpMessageFactory, $class_resolver);
  }

  /** * Tests createController(). * * @dataProvider providerTestCreateController */
  public function testCreateController($controller$class$output) {
    $this->container->set('some_service', new MockController());
    $result = $this->controllerResolver->getControllerFromDefinition($controller);
    $this->assertCallableController($result$class$output);
  }
Home | Imprint | This part of the site doesn't use cookies.