@@ -264,6 +264,32 @@ public function testInvalidAcceptHeader(): void
264
264
$ listener ->onKernelRequest ($ event );
265
265
}
266
266
267
+ public function testZeroAcceptHeader (): void
268
+ {
269
+ $ this ->expectException (NotAcceptableHttpException::class);
270
+ $ this ->expectExceptionMessage ('Requested format "0" is not supported. Supported MIME types are "application/octet-stream", "application/json" ' );
271
+
272
+ $ request = new Request ([], [], ['_api_resource_class ' => 'Foo ' , '_api_operation_name ' => 'get ' ]);
273
+ $ request ->headers ->set ('Accept ' , '0 ' );
274
+
275
+ $ eventProphecy = $ this ->prophesize (RequestEvent::class);
276
+ $ eventProphecy ->getRequest ()->willReturn ($ request );
277
+ $ event = $ eventProphecy ->reveal ();
278
+
279
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
280
+ $ resourceMetadataFactoryProphecy ->create ('Foo ' )->shouldBeCalled ()->willReturn (new ResourceMetadataCollection ('Foo ' , [
281
+ new ApiResource (operations: [
282
+ 'get ' => new Get (outputFormats: [
283
+ 'binary ' => ['application/octet-stream ' ],
284
+ 'json ' => ['application/json ' ],
285
+ ]),
286
+ ]),
287
+ ]));
288
+
289
+ $ listener = new AddFormatListener (new Negotiator (), $ resourceMetadataFactoryProphecy ->reveal ());
290
+ $ listener ->onKernelRequest ($ event );
291
+ }
292
+
267
293
public function testAcceptHeaderTakePrecedenceOverRequestFormat (): void
268
294
{
269
295
$ request = new Request ([], [], ['_api_resource_class ' => 'Foo ' , '_api_operation_name ' => 'get ' ]);
0 commit comments