1414use Prophecy \Prophecy \ObjectProphecy ;
1515use Symfony \Component \HttpFoundation \JsonResponse ;
1616use Symfony \Component \HttpFoundation \Request ;
17- use Symfony \Component \HttpFoundation \Response ;
1817use Symfony \Component \HttpKernel \Event \ExceptionEvent ;
1918use Symfony \Component \HttpKernel \HttpKernelInterface ;
2019
@@ -66,6 +65,12 @@ public function it_runs_on_json_route_formats(): void
6665 $ listener ->onKernelException ($ this ->event );
6766
6867 $ this ->assertNotNull ($ this ->event ->getResponse ());
68+ $ this ->assertEquals ([
69+ 'status ' => 500 ,
70+ 'type ' => 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html ' ,
71+ 'title ' => 'Internal Server Error ' ,
72+ 'detail ' => 'error ' ,
73+ ], json_decode ($ this ->event ->getResponse ()->getContent (), true ));
6974 }
7075
7176 /** @test */
@@ -75,8 +80,13 @@ public function it_runs_on_json_content_types(): void
7580 $ this ->request ->getRequestFormat ()->willReturn ('html ' );
7681 $ this ->request ->getContentType ()->willReturn ('application/json ' );
7782 $ listener ->onKernelException ($ this ->event );
78-
7983 $ this ->assertNotNull ($ this ->event ->getResponse ());
84+ $ this ->assertEquals ([
85+ 'status ' => 500 ,
86+ 'type ' => 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html ' ,
87+ 'title ' => 'Internal Server Error ' ,
88+ 'detail ' => 'error ' ,
89+ ], json_decode ($ this ->event ->getResponse ()->getContent (), true ));
8090 }
8191
8292 /** @test */
@@ -86,13 +96,6 @@ public function it_parses_an_api_problem_response(): void
8696 $ this ->request ->getRequestFormat ()->willReturn ('json ' );
8797 $ this ->request ->getContentType ()->willReturn ('application/json ' );
8898
89- $ this ->event ->setResponse (new JsonResponse ([
90- 'status ' => 500 ,
91- 'type ' => HttpApiProblem::TYPE_HTTP_RFC ,
92- 'title ' => HttpApiProblem::getTitleForStatusCode (500 ),
93- 'detail ' => 'error ' ,
94- ]));
95-
9699 $ listener ->onKernelException ($ this ->event );
97100 $ this ->assertJsonStringEqualsJsonString (
98101 json_encode ([
@@ -117,7 +120,6 @@ public function it_uses_an_exception_transformer(): void
117120
118121 $ this ->exceptionTransformer ->accepts (Argument::type (\Exception::class))->willReturn (true );
119122 $ this ->exceptionTransformer ->transform (Argument::type (\Exception::class))->willReturn ($ apiProblem ->reveal ());
120- $ this ->event ->setResponse (new Response (json_encode ([]), Response::HTTP_BAD_REQUEST , ['Content-Type ' => 'application/problem+json ' ]));
121123
122124 $ listener ->onKernelException ($ this ->event );
123125 $ this ->assertInstanceOf (JsonResponse::class, $ this ->event ->getResponse ());
0 commit comments