prophesize(HttpKernelInterface::class); $request = Request::create('/test'); $event = new GetResponseForExceptionEvent($kernel->reveal(), $request, 'GET', $exception); $subscriber = new ExceptionJsonSubscriber(); $subscriber->on4xx($event); $response = $event->getResponse(); $this->assertInstanceOf($expected_response_class, $response); $this->assertEquals('{"message":"test message"}', $response->getContent()); $this->assertEquals(405, $response->getStatusCode()); $this->assertEquals('POST, PUT', $response->headers->get('Allow')); $this->assertEquals('application/json', $response->headers->get('Content-Type')); } public function providerTestOn4xx() { return [ 'uncacheable exception' => [ new MethodNotAllowedHttpException(['POST', 'PUT'], 'test message'), JsonResponse::class, ], 'cacheable exception' => [ new CacheableMethodNotAllowedHttpException((new CacheableMetadata())->setCacheContexts(['route']), ['POST', 'PUT'], 'test message'), CacheableJsonResponse::class, ], ]; } }