@@ -57,7 +57,7 @@ public function testValidationException(): void
57
57
$ list = new ConstraintViolationList ([]);
58
58
59
59
$ serializerProphecy = $ this ->prophesize (SerializerInterface::class);
60
- $ serializerProphecy ->serialize ($ list , 'hydra ' )->willReturn ($ exceptionJson )->shouldBeCalled ();
60
+ $ serializerProphecy ->serialize ($ list , 'hydra ' , [] )->willReturn ($ exceptionJson )->shouldBeCalled ();
61
61
62
62
$ listener = new ValidationExceptionListener ($ serializerProphecy ->reveal (), ['hydra ' => ['application/ld+json ' ]]);
63
63
$ event = new ExceptionEvent ($ this ->prophesize (HttpKernelInterface::class)->reveal (), new Request (), \defined (HttpKernelInterface::class.'::MAIN_REQUEST ' ) ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST , new ValidationException ($ list ));
@@ -89,7 +89,7 @@ public function getConstraintViolationList(): ConstraintViolationListInterface
89
89
};
90
90
91
91
$ serializerProphecy = $ this ->prophesize (SerializerInterface::class);
92
- $ serializerProphecy ->serialize ($ constraintViolationList , 'hydra ' )->willReturn ($ serializedConstraintViolationList )->shouldBeCalledOnce ();
92
+ $ serializerProphecy ->serialize ($ constraintViolationList , 'hydra ' , [] )->willReturn ($ serializedConstraintViolationList )->shouldBeCalledOnce ();
93
93
94
94
$ exceptionEvent = new ExceptionEvent (
95
95
$ this ->prophesize (HttpKernelInterface::class)->reveal (),
@@ -120,7 +120,7 @@ public function testValidationFilterException(): void
120
120
$ exception = new FilterValidationException ([], 'my message ' );
121
121
122
122
$ serializerProphecy = $ this ->prophesize (SerializerInterface::class);
123
- $ serializerProphecy ->serialize ($ exception , 'hydra ' )->willReturn ($ exceptionJson )->shouldBeCalled ();
123
+ $ serializerProphecy ->serialize ($ exception , 'hydra ' , [] )->willReturn ($ exceptionJson )->shouldBeCalled ();
124
124
125
125
$ listener = new ValidationExceptionListener ($ serializerProphecy ->reveal (), ['hydra ' => ['application/ld+json ' ]]);
126
126
$ event = new ExceptionEvent ($ this ->prophesize (HttpKernelInterface::class)->reveal (), new Request (), \defined (HttpKernelInterface::class.'::MAIN_REQUEST ' ) ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST , $ exception );
@@ -134,4 +134,25 @@ public function testValidationFilterException(): void
134
134
$ this ->assertSame ('nosniff ' , $ response ->headers ->get ('X-Content-Type-Options ' ));
135
135
$ this ->assertSame ('deny ' , $ response ->headers ->get ('X-Frame-Options ' ));
136
136
}
137
+
138
+ public function testValidationExceptionWithHydraTitle (): void
139
+ {
140
+ $ exceptionJson = '{"foo": "bar"} ' ;
141
+ $ list = new ConstraintViolationList ([]);
142
+
143
+ $ serializerProphecy = $ this ->prophesize (SerializerInterface::class);
144
+ $ serializerProphecy ->serialize ($ list , 'hydra ' , ['title ' => 'foo ' ])->willReturn ($ exceptionJson )->shouldBeCalled ();
145
+
146
+ $ listener = new ValidationExceptionListener ($ serializerProphecy ->reveal (), ['hydra ' => ['application/ld+json ' ]]);
147
+ $ event = new ExceptionEvent ($ this ->prophesize (HttpKernelInterface::class)->reveal (), new Request (), \defined (HttpKernelInterface::class.'::MAIN_REQUEST ' ) ? HttpKernelInterface::MAIN_REQUEST : HttpKernelInterface::MASTER_REQUEST , new ValidationException ($ list , errorTitle: 'foo ' ));
148
+ $ listener ->onKernelException ($ event );
149
+
150
+ $ response = $ event ->getResponse ();
151
+ $ this ->assertInstanceOf (Response::class, $ response );
152
+ $ this ->assertSame ($ exceptionJson , $ response ->getContent ());
153
+ $ this ->assertSame (Response::HTTP_UNPROCESSABLE_ENTITY , $ response ->getStatusCode ());
154
+ $ this ->assertSame ('application/ld+json; charset=utf-8 ' , $ response ->headers ->get ('Content-Type ' ));
155
+ $ this ->assertSame ('nosniff ' , $ response ->headers ->get ('X-Content-Type-Options ' ));
156
+ $ this ->assertSame ('deny ' , $ response ->headers ->get ('X-Frame-Options ' ));
157
+ }
137
158
}
0 commit comments