@@ -32,7 +32,7 @@ public function testNoResourceClass()
32
32
$ request = new Request ();
33
33
34
34
$ eventProphecy = $ this ->prophesize (GetResponseEvent::class);
35
- $ eventProphecy ->getRequest ()->willReturn ($ request )-> shouldBeCalled () ;
35
+ $ eventProphecy ->getRequest ()->willReturn ($ request );
36
36
$ event = $ eventProphecy ->reveal ();
37
37
38
38
$ formatsProviderProphecy = $ this ->prophesize (FormatsProviderInterface::class);
@@ -50,11 +50,11 @@ public function testSupportedRequestFormat()
50
50
$ request ->setRequestFormat ('xml ' );
51
51
52
52
$ eventProphecy = $ this ->prophesize (GetResponseEvent::class);
53
- $ eventProphecy ->getRequest ()->willReturn ($ request )-> shouldBeCalled () ;
53
+ $ eventProphecy ->getRequest ()->willReturn ($ request );
54
54
$ event = $ eventProphecy ->reveal ();
55
55
56
56
$ formatsProviderProphecy = $ this ->prophesize (FormatsProviderInterface::class);
57
- $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['xml ' => ['text/xml ' ]])-> shouldBeCalled () ;
57
+ $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['xml ' => ['text/xml ' ]]);
58
58
59
59
$ listener = new AddFormatListener (new Negotiator (), $ formatsProviderProphecy ->reveal ());
60
60
$ listener ->onKernelRequest ($ event );
@@ -69,11 +69,11 @@ public function testRespondFlag()
69
69
$ request ->setRequestFormat ('xml ' );
70
70
71
71
$ eventProphecy = $ this ->prophesize (GetResponseEvent::class);
72
- $ eventProphecy ->getRequest ()->willReturn ($ request )-> shouldBeCalled () ;
72
+ $ eventProphecy ->getRequest ()->willReturn ($ request );
73
73
$ event = $ eventProphecy ->reveal ();
74
74
75
75
$ formatsProviderProphecy = $ this ->prophesize (FormatsProviderInterface::class);
76
- $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['xml ' => ['text/xml ' ]])-> shouldBeCalled () ;
76
+ $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['xml ' => ['text/xml ' ]]);
77
77
78
78
$ listener = new AddFormatListener (new Negotiator (), $ formatsProviderProphecy ->reveal ());
79
79
$ listener ->onKernelRequest ($ event );
@@ -91,10 +91,11 @@ public function testUnsupportedRequestFormat()
91
91
$ request ->setRequestFormat ('xml ' );
92
92
93
93
$ eventProphecy = $ this ->prophesize (GetResponseEvent::class);
94
- $ eventProphecy ->getRequest ()->willReturn ($ request )-> shouldBeCalled () ;
94
+ $ eventProphecy ->getRequest ()->willReturn ($ request );
95
95
$ event = $ eventProphecy ->reveal ();
96
+
96
97
$ formatsProviderProphecy = $ this ->prophesize (FormatsProviderInterface::class);
97
- $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['json ' => ['application/json ' ]])-> shouldBeCalled () ;
98
+ $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['json ' => ['application/json ' ]]);
98
99
99
100
$ listener = new AddFormatListener (new Negotiator (), $ formatsProviderProphecy ->reveal ());
100
101
$ listener ->onKernelRequest ($ event );
@@ -108,11 +109,11 @@ public function testSupportedAcceptHeader()
108
109
$ request ->headers ->set ('Accept ' , 'text/html, application/xhtml+xml, application/xml, application/json;q=0.9, */*;q=0.8 ' );
109
110
110
111
$ eventProphecy = $ this ->prophesize (GetResponseEvent::class);
111
- $ eventProphecy ->getRequest ()->willReturn ($ request )-> shouldBeCalled () ;
112
+ $ eventProphecy ->getRequest ()->willReturn ($ request );
112
113
$ event = $ eventProphecy ->reveal ();
113
114
114
115
$ formatsProviderProphecy = $ this ->prophesize (FormatsProviderInterface::class);
115
- $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['binary ' => ['application/octet-stream ' ], 'json ' => ['application/json ' ]])-> shouldBeCalled () ;
116
+ $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['binary ' => ['application/octet-stream ' ], 'json ' => ['application/json ' ]]);
116
117
117
118
$ listener = new AddFormatListener (new Negotiator (), $ formatsProviderProphecy ->reveal ());
118
119
$ listener ->onKernelRequest ($ event );
@@ -126,11 +127,11 @@ public function testAcceptAllHeader()
126
127
$ request ->headers ->set ('Accept ' , 'text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8 ' );
127
128
128
129
$ eventProphecy = $ this ->prophesize (GetResponseEvent::class);
129
- $ eventProphecy ->getRequest ()->willReturn ($ request )-> shouldBeCalled () ;
130
+ $ eventProphecy ->getRequest ()->willReturn ($ request );
130
131
$ event = $ eventProphecy ->reveal ();
131
132
132
133
$ formatsProviderProphecy = $ this ->prophesize (FormatsProviderInterface::class);
133
- $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['binary ' => ['application/octet-stream ' ], 'json ' => ['application/json ' ]])-> shouldBeCalled () ;
134
+ $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['binary ' => ['application/octet-stream ' ], 'json ' => ['application/json ' ]]);
134
135
135
136
$ listener = new AddFormatListener (new Negotiator (), $ formatsProviderProphecy ->reveal ());
136
137
$ listener ->onKernelRequest ($ event );
@@ -148,11 +149,30 @@ public function testUnsupportedAcceptHeader()
148
149
$ request ->headers ->set ('Accept ' , 'text/html, application/xhtml+xml, application/xml;q=0.9 ' );
149
150
150
151
$ eventProphecy = $ this ->prophesize (GetResponseEvent::class);
151
- $ eventProphecy ->getRequest ()->willReturn ($ request )->shouldBeCalled ();
152
+ $ eventProphecy ->getRequest ()->willReturn ($ request );
153
+ $ event = $ eventProphecy ->reveal ();
154
+
155
+ $ formatsProviderProphecy = $ this ->prophesize (FormatsProviderInterface::class);
156
+ $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['binary ' => ['application/octet-stream ' ], 'json ' => ['application/json ' ]]);
157
+
158
+ $ listener = new AddFormatListener (new Negotiator (), $ formatsProviderProphecy ->reveal ());
159
+ $ listener ->onKernelRequest ($ event );
160
+ }
161
+
162
+ public function testUnsupportedAcceptHeaderSymfonyBuiltInFormat ()
163
+ {
164
+ $ this ->expectException (NotAcceptableHttpException::class);
165
+ $ this ->expectExceptionMessage ('Requested format "text/xml" is not supported. Supported MIME types are "application/json". ' );
166
+
167
+ $ request = new Request ([], [], ['_api_resource_class ' => 'Foo ' ]);
168
+ $ request ->headers ->set ('Accept ' , 'text/xml ' );
169
+
170
+ $ eventProphecy = $ this ->prophesize (GetResponseEvent::class);
171
+ $ eventProphecy ->getRequest ()->willReturn ($ request );
152
172
$ event = $ eventProphecy ->reveal ();
153
173
154
174
$ formatsProviderProphecy = $ this ->prophesize (FormatsProviderInterface::class);
155
- $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['binary ' => [ ' application/octet-stream ' ], ' json ' => ['application/json ' ]])-> shouldBeCalled ( );
175
+ $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['json ' => ['application/json ' ]]);
156
176
157
177
$ listener = new AddFormatListener (new Negotiator (), $ formatsProviderProphecy ->reveal ());
158
178
$ listener ->onKernelRequest ($ event );
@@ -167,11 +187,11 @@ public function testInvalidAcceptHeader()
167
187
$ request ->headers ->set ('Accept ' , 'invalid ' );
168
188
169
189
$ eventProphecy = $ this ->prophesize (GetResponseEvent::class);
170
- $ eventProphecy ->getRequest ()->willReturn ($ request )-> shouldBeCalled () ;
190
+ $ eventProphecy ->getRequest ()->willReturn ($ request );
171
191
$ event = $ eventProphecy ->reveal ();
172
192
173
193
$ formatsProviderProphecy = $ this ->prophesize (FormatsProviderInterface::class);
174
- $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['json ' => ['application/json ' ]])-> shouldBeCalled () ;
194
+ $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['json ' => ['application/json ' ]]);
175
195
176
196
$ listener = new AddFormatListener (new Negotiator (), $ formatsProviderProphecy ->reveal ());
177
197
$ listener ->onKernelRequest ($ event );
@@ -184,11 +204,11 @@ public function testAcceptHeaderTakePrecedenceOverRequestFormat()
184
204
$ request ->setRequestFormat ('xml ' );
185
205
186
206
$ eventProphecy = $ this ->prophesize (GetResponseEvent::class);
187
- $ eventProphecy ->getRequest ()->willReturn ($ request )-> shouldBeCalled () ;
207
+ $ eventProphecy ->getRequest ()->willReturn ($ request );
188
208
$ event = $ eventProphecy ->reveal ();
189
209
190
210
$ formatsProviderProphecy = $ this ->prophesize (FormatsProviderInterface::class);
191
- $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['xml ' => ['application/xml ' ], 'json ' => ['application/json ' ]])-> shouldBeCalled () ;
211
+ $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['xml ' => ['application/xml ' ], 'json ' => ['application/json ' ]]);
192
212
193
213
$ listener = new AddFormatListener (new Negotiator (), $ formatsProviderProphecy ->reveal ());
194
214
$ listener ->onKernelRequest ($ event );
@@ -204,11 +224,11 @@ public function testInvalidRouteFormat()
204
224
$ request = new Request ([], [], ['_api_resource_class ' => 'Foo ' , '_format ' => 'invalid ' ]);
205
225
206
226
$ eventProphecy = $ this ->prophesize (GetResponseEvent::class);
207
- $ eventProphecy ->getRequest ()->willReturn ($ request )-> shouldBeCalled () ;
227
+ $ eventProphecy ->getRequest ()->willReturn ($ request );
208
228
$ event = $ eventProphecy ->reveal ();
209
229
210
230
$ formatsProviderProphecy = $ this ->prophesize (FormatsProviderInterface::class);
211
- $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['json ' => ['application/json ' ]])-> shouldBeCalled () ;
231
+ $ formatsProviderProphecy ->getFormatsFromAttributes ([])->willReturn (['json ' => ['application/json ' ]]);
212
232
213
233
$ listener = new AddFormatListener (new Negotiator (), $ formatsProviderProphecy ->reveal ());
214
234
$ listener ->onKernelRequest ($ event );
@@ -220,11 +240,11 @@ public function testResourceClassSupportedRequestFormat()
220
240
$ request ->setRequestFormat ('csv ' );
221
241
222
242
$ eventProphecy = $ this ->prophesize (GetResponseEvent::class);
223
- $ eventProphecy ->getRequest ()->willReturn ($ request )-> shouldBeCalled () ;
243
+ $ eventProphecy ->getRequest ()->willReturn ($ request );
224
244
$ event = $ eventProphecy ->reveal ();
225
245
226
246
$ formatsProviderProphecy = $ this ->prophesize (FormatsProviderInterface::class);
227
- $ formatsProviderProphecy ->getFormatsFromAttributes (['resource_class ' => 'Foo ' , 'collection_operation_name ' => 'get ' , 'receive ' => true ])->willReturn (['csv ' => ['text/csv ' ]])-> shouldBeCalled () ;
247
+ $ formatsProviderProphecy ->getFormatsFromAttributes (['resource_class ' => 'Foo ' , 'collection_operation_name ' => 'get ' , 'receive ' => true ])->willReturn (['csv ' => ['text/csv ' ]]);
228
248
229
249
$ listener = new AddFormatListener (new Negotiator (), $ formatsProviderProphecy ->reveal ());
230
250
$ listener ->onKernelRequest ($ event );
0 commit comments