@@ -32,7 +32,7 @@ public function testNoResourceClass()
32
32
$ eventProphecy ->getRequest ()->willReturn ($ request )->shouldBeCalled ();
33
33
$ event = $ eventProphecy ->reveal ();
34
34
35
- $ listener = new AddFormatListener (new Negotiator (), ['notexist ' => 'application/vnd.notexist ' ]);
35
+ $ listener = new AddFormatListener (new Negotiator (), ['notexist ' => 'application/vnd.notexist ' ], [] );
36
36
$ listener ->onKernelRequest ($ event );
37
37
38
38
$ this ->assertNull ($ request ->getFormat ('application/vnd.notexist ' ));
@@ -47,7 +47,7 @@ public function testSupportedRequestFormat()
47
47
$ eventProphecy ->getRequest ()->willReturn ($ request )->shouldBeCalled ();
48
48
$ event = $ eventProphecy ->reveal ();
49
49
50
- $ listener = new AddFormatListener (new Negotiator (), ['xml ' => ['text/xml ' ]]);
50
+ $ listener = new AddFormatListener (new Negotiator (), ['xml ' => ['text/xml ' ]], [] );
51
51
$ listener ->onKernelRequest ($ event );
52
52
53
53
$ this ->assertSame ('xml ' , $ request ->getRequestFormat ());
@@ -63,7 +63,7 @@ public function testRespondFlag()
63
63
$ eventProphecy ->getRequest ()->willReturn ($ request )->shouldBeCalled ();
64
64
$ event = $ eventProphecy ->reveal ();
65
65
66
- $ listener = new AddFormatListener (new Negotiator (), ['xml ' => ['text/xml ' ]]);
66
+ $ listener = new AddFormatListener (new Negotiator (), ['xml ' => ['text/xml ' ]], [] );
67
67
$ listener ->onKernelRequest ($ event );
68
68
69
69
$ this ->assertSame ('xml ' , $ request ->getRequestFormat ());
@@ -83,7 +83,7 @@ public function testUnsupportedRequestFormat()
83
83
$ eventProphecy ->getRequest ()->willReturn ($ request )->shouldBeCalled ();
84
84
$ event = $ eventProphecy ->reveal ();
85
85
86
- $ listener = new AddFormatListener (new Negotiator (), ['json ' => ['application/json ' ]]);
86
+ $ listener = new AddFormatListener (new Negotiator (), ['json ' => ['application/json ' ]], [] );
87
87
$ listener ->onKernelRequest ($ event );
88
88
89
89
$ this ->assertSame ('json ' , $ request ->getRequestFormat ());
@@ -98,7 +98,7 @@ public function testSupportedAcceptHeader()
98
98
$ eventProphecy ->getRequest ()->willReturn ($ request )->shouldBeCalled ();
99
99
$ event = $ eventProphecy ->reveal ();
100
100
101
- $ listener = new AddFormatListener (new Negotiator (), ['binary ' => ['application/octet-stream ' ], 'json ' => ['application/json ' ]]);
101
+ $ listener = new AddFormatListener (new Negotiator (), ['binary ' => ['application/octet-stream ' ], 'json ' => ['application/json ' ]], [] );
102
102
$ listener ->onKernelRequest ($ event );
103
103
104
104
$ this ->assertSame ('json ' , $ request ->getRequestFormat ());
@@ -113,7 +113,7 @@ public function testAcceptAllHeader()
113
113
$ eventProphecy ->getRequest ()->willReturn ($ request )->shouldBeCalled ();
114
114
$ event = $ eventProphecy ->reveal ();
115
115
116
- $ listener = new AddFormatListener (new Negotiator (), ['binary ' => ['application/octet-stream ' ], 'json ' => ['application/json ' ]]);
116
+ $ listener = new AddFormatListener (new Negotiator (), ['binary ' => ['application/octet-stream ' ], 'json ' => ['application/json ' ]], [] );
117
117
$ listener ->onKernelRequest ($ event );
118
118
119
119
$ this ->assertSame ('binary ' , $ request ->getRequestFormat ());
@@ -133,7 +133,7 @@ public function testUnsupportedAcceptHeader()
133
133
$ eventProphecy ->getRequest ()->willReturn ($ request )->shouldBeCalled ();
134
134
$ event = $ eventProphecy ->reveal ();
135
135
136
- $ listener = new AddFormatListener (new Negotiator (), ['binary ' => ['application/octet-stream ' ], 'json ' => ['application/json ' ]]);
136
+ $ listener = new AddFormatListener (new Negotiator (), ['binary ' => ['application/octet-stream ' ], 'json ' => ['application/json ' ]], [] );
137
137
$ listener ->onKernelRequest ($ event );
138
138
}
139
139
@@ -150,7 +150,7 @@ public function testInvalidAcceptHeader()
150
150
$ eventProphecy ->getRequest ()->willReturn ($ request )->shouldBeCalled ();
151
151
$ event = $ eventProphecy ->reveal ();
152
152
153
- $ listener = new AddFormatListener (new Negotiator (), ['json ' => ['application/json ' ]]);
153
+ $ listener = new AddFormatListener (new Negotiator (), ['json ' => ['application/json ' ]], [] );
154
154
$ listener ->onKernelRequest ($ event );
155
155
}
156
156
@@ -164,7 +164,7 @@ public function testAcceptHeaderTakePrecedenceOverRequestFormat()
164
164
$ eventProphecy ->getRequest ()->willReturn ($ request )->shouldBeCalled ();
165
165
$ event = $ eventProphecy ->reveal ();
166
166
167
- $ listener = new AddFormatListener (new Negotiator (), ['xml ' => ['application/xml ' ], 'json ' => ['application/json ' ]]);
167
+ $ listener = new AddFormatListener (new Negotiator (), ['xml ' => ['application/xml ' ], 'json ' => ['application/json ' ]], [] );
168
168
$ listener ->onKernelRequest ($ event );
169
169
170
170
$ this ->assertSame ('json ' , $ request ->getRequestFormat ());
@@ -182,7 +182,42 @@ public function testInvalidRouteFormat()
182
182
$ eventProphecy ->getRequest ()->willReturn ($ request )->shouldBeCalled ();
183
183
$ event = $ eventProphecy ->reveal ();
184
184
185
- $ listener = new AddFormatListener (new Negotiator (), ['json ' => ['application/json ' ]]);
185
+ $ listener = new AddFormatListener (new Negotiator (), ['json ' => ['application/json ' ]], [] );
186
186
$ listener ->onKernelRequest ($ event );
187
187
}
188
+
189
+ public function testSupportedDocumentationAcceptHeader ()
190
+ {
191
+ $ request = new Request ([], [], ['_api_respond ' => '1 ' , '_controller ' => 'api_platform.action.documentation ' ]);
192
+ $ request ->setRequestFormat ('json ' );
193
+
194
+ $ eventProphecy = $ this ->prophesize (GetResponseEvent::class);
195
+ $ eventProphecy ->getRequest ()->willReturn ($ request )->shouldBeCalled ();
196
+ $ event = $ eventProphecy ->reveal ();
197
+
198
+ $ listener = new AddFormatListener (new Negotiator (), ['xml ' => ['text/xml ' ]], ['json ' => ['application/json ' ]]);
199
+ $ listener ->onKernelRequest ($ event );
200
+
201
+ $ this ->assertSame ('json ' , $ request ->getRequestFormat ());
202
+ $ this ->assertSame ('application/json ' , $ request ->getMimeType ($ request ->getRequestFormat ()));
203
+ }
204
+
205
+ /**
206
+ * @expectedException \Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException
207
+ * @expectedExceptionMessage Requested format "application/ld+json" is not supported. Supported MIME types are "application/json".
208
+ */
209
+ public function testUnsupportedDocumentationRequestFormat ()
210
+ {
211
+ $ request = new Request ([], [], ['_api_respond ' => '1 ' , '_controller ' => 'api_platform.action.documentation ' ]);
212
+ $ request ->setRequestFormat ('jsonld ' );
213
+
214
+ $ eventProphecy = $ this ->prophesize (GetResponseEvent::class);
215
+ $ eventProphecy ->getRequest ()->willReturn ($ request )->shouldBeCalled ();
216
+ $ event = $ eventProphecy ->reveal ();
217
+
218
+ $ listener = new AddFormatListener (new Negotiator (), ['xml ' => ['text/xml ' ]], ['json ' => ['application/json ' ]]);
219
+ $ listener ->onKernelRequest ($ event );
220
+
221
+ $ this ->assertSame ('json ' , $ request ->getRequestFormat ());
222
+ }
188
223
}
0 commit comments