testProcessWithCallableController(); $this->testProcessWithControllerMethod(); $this->testProcessWithControllerMethodNotExist(); } public function testProcessWithCallableController() { $container = new ContainerMock(); $controllerMiddleware = new ControllerMiddleware($container); $request = new ServerRequestMock([ RouterMiddleware::ATTRIBUTE_KEY => new Route('example', '/example', [new SampleControllerTest([])]) ]); $handler = new RequestHandlerMock(); $response = $controllerMiddleware->process($request, $handler); $this->assertInstanceOf(ResponseInterface::class, $response); } public function testProcessWithControllerMethod() { $response = $this->testProcessWithController('fakeMethod'); $this->assertInstanceOf(ResponseInterface::class, $response); } public function testProcessWithControllerMethodNotExist() { $this->expectException(\BadMethodCallException::class, function () { $this->testProcessWithController('fakeMethodNotExist'); }); } private function testProcessWithController(string $controllerMethodName): ResponseInterface { $controllerClassName = SampleControllerTest::class; $container = new ContainerMock([ $controllerClassName => new SampleControllerTest([]) ]); $controllerMiddleware = new ControllerMiddleware($container); $request = new ServerRequestMock([ RouterMiddleware::ATTRIBUTE_KEY => new Route('example', '/example', [$controllerClassName, $controllerMethodName]) ]); return $controllerMiddleware->process($request, new RequestHandlerMock()); } }