@@ -213,12 +213,49 @@ public function testApplicationJsonIncludesObjectSerialized()
213213 $ this ->assertJson ($ request ->getContent ());
214214 }
215215
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+
216253 /**
217254 * @param string $method
218255 *
219256 * @dataProvider queryParamsAwareMethods
220257 */
221- public function testGetApplicationJsonNotIncludesJsonAsContent ($ method )
258+ public function testJsonRequestBodyIsNotSentForThisMethod ($ method )
222259 {
223260 $ this ->module ->haveHttpHeader ('Content-Type ' , 'application/json ' );
224261 $ this ->module ->send ($ method , '/ ' , ['name ' => 'john ' ]);
@@ -228,12 +265,26 @@ public function testGetApplicationJsonNotIncludesJsonAsContent($method)
228265 $ this ->assertContains ('john ' , $ request ->getParameters ());
229266 }
230267
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+
231283 public function queryParamsAwareMethods ()
232284 {
233285 return [
234286 'GET ' => ['GET ' ],
235287 'HEAD ' => ['HEAD ' ],
236- 'DELETE ' => ['DELETE ' ],
237288 'OPTIONS ' => ['OPTIONS ' ],
238289 ];
239290 }
0 commit comments