app = $this->makeEmpty(App::class, [ 'getResponseFactory' => $this->makeEmpty(ResponseFactoryInterface::class, [ 'createResponse' => $this->makeEmpty(ResponseInterface::class, [ 'getBody' => $this->makeEmpty(StreamInterface::class, [ 'write' => function (mixed $data) { $this->assertIsString($data); $this->assertJson($data); }, ]), ]), ]), ]); /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ $this->request = $this->makeEmpty(ServerRequestInterface::class, [ 'getAttribute' => function($name) { return match ($name) { RouteContext::ROUTE_PARSER => $this->makeEmpty(RouteParserInterface::class), RouteContext::ROUTING_RESULTS => $this->makeEmpty(RoutingResults::class), default => null, }; } ]); } /** * @throws Exception */ public function testUseWithLogger(): void { /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ $this->exception = $this->make(Exception::class, [ 'message' => '', 'code' => 400, 'file' => '/path(to/file', ]); /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ $this->logger = $this->makeEmpty(LoggerInterface::class, [ 'error' => Expected::once(), ]); $middleWare = new ErrorHandler($this->app); $middleWare($this->request, $this->exception, true, true, true, $this->logger); } /** * @throws Exception */ public function testUseWithHttpException(): void { /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ $this->exception = $this->make(HttpException::class, [ 'message' => '', 'code' => 400, 'file' => '/path(to/file', 'getTitle' => Expected::once('The Title'), ]); /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ $this->logger = $this->makeEmpty(LoggerInterface::class, []); $middleWare = new ErrorHandler($this->app); $middleWare($this->request, $this->exception, true, true, true, $this->logger); } /** * @throws Exception */ public function testUseWithGeneralException(): void { /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ $this->exception = $this->make(Exception::class, [ 'message' => '', 'code' => 400, 'file' => '/path(to/file', ]); /** @noinspection PhpFieldAssignmentTypeMismatchInspection */ $this->logger = $this->makeEmpty(LoggerInterface::class, []); $middleWare = new ErrorHandler($this->app); $middleWare($this->request, $this->exception, true, true, true, $this->logger); } }