expectException($expectedException); $handler = new MockHandler([$response]); $middleware = new ResponseConverterMiddleware($handler); $middleware($request, [])->wait(); } public function getResponses(): iterable { yield [ new Request('GET', 'http://localhost'), new Response(204, [], ''), Exception\NoContentException::class, ]; yield [ new Request('GET', 'http://localhost'), new Response( 403, ['Content-Type' => 'application/json'], '{"error":"ForbiddenOperationException","errorMessage":"Invalid token"}' ), Exception\ForbiddenException::class, ]; yield [ new Request('GET', 'http://localhost'), new Response( 429, ['Content-Type' => 'application/json'], '{"error":"TooManyRequestsException","errorMessage":"The client has sent too many requests within a certain amount of time"}' ), Exception\TooManyRequestsException::class, ]; } }