errorHandler = new JsonErrorResponseGenerator(); } /** @test */ public function noErrorStatusReturnsInternalServerError(): void { /** @var Response\JsonResponse $response */ $response = $this->errorHandler->__invoke(null, new ServerRequest(), new Response()); $payload = $response->getPayload(); $this->assertInstanceOf(Response\JsonResponse::class, $response); $this->assertEquals(500, $response->getStatusCode()); $this->assertEquals('Internal Server Error', $payload['message']); } /** * @test * @dataProvider provideStatus */ public function errorStatusReturnsThatStatus(int $status, string $message): void { /** @var Response\JsonResponse $response */ $response = $this->errorHandler->__invoke( null, new ServerRequest(), (new Response())->withStatus($status, $message) ); $payload = $response->getPayload(); $this->assertInstanceOf(Response\JsonResponse::class, $response); $this->assertEquals($status, $response->getStatusCode()); $this->assertEquals($message, $payload['message']); } public function provideStatus(): iterable { return array_map(function (int $status) { return [$status, 'Some message']; }, range(400, 500, 20)); } }