@@ -213,12 +213,49 @@ public function testApplicationJsonIncludesObjectSerialized()
213
213
$ this ->assertJson ($ request ->getContent ());
214
214
}
215
215
216
+ /**
217
+ * @param string $method
218
+ *
219
+ * @dataProvider requestBodyAwareMethods
220
+ */
221
+ public function testRequestBodyIsSentAsJsonForThisMethod ($ method )
222
+ {
223
+ $ this ->module ->haveHttpHeader ('Content-Type ' , 'application/json ' );
224
+ $ this ->module ->send ($ method , '/ ' , ['name ' => 'john ' ]);
225
+ /** @var $request \Symfony\Component\BrowserKit\Request **/
226
+ $ request = $ this ->module ->client ->getRequest ();
227
+ $ this ->assertSame (json_encode (['name ' => 'john ' ]), $ request ->getContent ());
228
+ }
229
+
230
+ /**
231
+ * @param string $method
232
+ *
233
+ * @dataProvider requestBodyAwareMethods
234
+ */
235
+ public function testRequestBodyIsSentUrlEncodedForThisMethod ($ method )
236
+ {
237
+ $ this ->module ->send ($ method , '/ ' , ['name ' => 'john ' ]);
238
+ /** @var $request \Symfony\Component\BrowserKit\Request **/
239
+ $ request = $ this ->module ->client ->getRequest ();
240
+ $ this ->assertSame (http_build_query (['name ' => 'john ' ]), $ request ->getContent ());
241
+ }
242
+
243
+ public function requestBodyAwareMethods ()
244
+ {
245
+ return [
246
+ 'POST ' => ['POST ' ],
247
+ 'PUT ' => ['PUT ' ],
248
+ 'PATCH ' => ['PATCH ' ],
249
+ 'DELETE ' => ['DELETE ' ],
250
+ ];
251
+ }
252
+
216
253
/**
217
254
* @param string $method
218
255
*
219
256
* @dataProvider queryParamsAwareMethods
220
257
*/
221
- public function testGetApplicationJsonNotIncludesJsonAsContent ($ method )
258
+ public function testJsonRequestBodyIsNotSentForThisMethod ($ method )
222
259
{
223
260
$ this ->module ->haveHttpHeader ('Content-Type ' , 'application/json ' );
224
261
$ this ->module ->send ($ method , '/ ' , ['name ' => 'john ' ]);
@@ -228,12 +265,26 @@ public function testGetApplicationJsonNotIncludesJsonAsContent($method)
228
265
$ this ->assertContains ('john ' , $ request ->getParameters ());
229
266
}
230
267
268
+
269
+ /**
270
+ * @param string $method
271
+ *
272
+ * @dataProvider queryParamsAwareMethods
273
+ */
274
+ public function testUrlEncodedRequestBodyIsNotSentForThisMethod ($ method )
275
+ {
276
+ $ this ->module ->send ($ method , '/ ' , ['name ' => 'john ' ]);
277
+ /** @var $request \Symfony\Component\BrowserKit\Request **/
278
+ $ request = $ this ->module ->client ->getRequest ();
279
+ $ this ->assertNull ($ request ->getContent ());
280
+ $ this ->assertContains ('john ' , $ request ->getParameters ());
281
+ }
282
+
231
283
public function queryParamsAwareMethods ()
232
284
{
233
285
return [
234
286
'GET ' => ['GET ' ],
235
287
'HEAD ' => ['HEAD ' ],
236
- 'DELETE ' => ['DELETE ' ],
237
288
'OPTIONS ' => ['OPTIONS ' ],
238
289
];
239
290
}
0 commit comments