@@ -14,7 +14,7 @@ public function convertGetRequest(FunctionalTester $I): void
1414 $ I ->haveHttpHeader ('Cookie ' , 'name=value; name2=value2; name3=value3 ' );
1515 $ I ->haveServerParameter ('custom ' , 'server ' );
1616
17- $ I ->sendGET ('/hello/John/Doe ' , ['foo ' => 'bar ' ]);
17+ $ I ->sendGet ('/hello/John/Doe ' , ['foo ' => 'bar ' ]);
1818
1919 $ I ->seeResponseCodeIs (200 );
2020 $ response = json_decode ($ I ->grabResponse (), true );
@@ -44,10 +44,11 @@ public function convertGetRequest(FunctionalTester $I): void
4444 // Check headers.
4545 $ I ->assertSame (
4646 [
47- 'User-Agent ' => ['Symfony BrowserKit ' ],
48- 'Custom ' => ['header ' ],
49- 'Cookie ' => ['name=value; name2=value2; name3=value3 ' ],
50- 'Host ' => ['localhost ' ],
47+ 'User-Agent ' => ['Symfony BrowserKit ' ],
48+ 'X-Default-Header ' => ['default-value ' ],
49+ 'Custom ' => ['header ' ],
50+ 'Cookie ' => ['name=value; name2=value2; name3=value3 ' ],
51+ 'Host ' => ['localhost ' ],
5152 ],
5253 $ response ['headers ' ],
5354 'Header parameters are not identical. '
@@ -74,7 +75,7 @@ public function convertPostMultipartFormDataRequest(FunctionalTester $I): void
7475 $ I ->haveHttpHeader ('Cookie ' , 'name=value; name2=value2; name3=value3 ' );
7576 $ I ->haveServerParameter ('custom ' , 'server ' );
7677
77- $ I ->sendPOST ('/hello/John/Doe?query=value ' , ['foo ' => 'bar ' ]);
78+ $ I ->sendPost ('/hello/John/Doe?query=value ' , ['foo ' => 'bar ' ]);
7879
7980 $ I ->seeResponseCodeIs (200 );
8081 $ response = json_decode ($ I ->grabResponse (), true );
@@ -104,10 +105,11 @@ public function convertPostMultipartFormDataRequest(FunctionalTester $I): void
104105 // Check headers.
105106 $ I ->assertSame (
106107 [
107- 'User-Agent ' => ['Symfony BrowserKit ' ],
108- 'Content-Type ' => ['multipart/form-data ' ],
109- 'Cookie ' => ['name=value; name2=value2; name3=value3 ' ],
110- 'Host ' => ['localhost ' ],
108+ 'User-Agent ' => ['Symfony BrowserKit ' ],
109+ 'X-Default-Header ' => ['default-value ' ],
110+ 'Content-Type ' => ['multipart/form-data ' ],
111+ 'Cookie ' => ['name=value; name2=value2; name3=value3 ' ],
112+ 'Host ' => ['localhost ' ],
111113 ],
112114 $ response ['headers ' ],
113115 'Header parameters are not identical. '
@@ -134,7 +136,7 @@ public function convertPostJsonRequest(FunctionalTester $I): void
134136 $ I ->haveHttpHeader ('Cookie ' , 'name=value; name2=value2; name3=value3 ' );
135137 $ I ->haveServerParameter ('custom ' , 'server ' );
136138
137- $ I ->sendPOST ('/hello/John/Doe?query=value ' , ['foo ' => 'bar ' ]);
139+ $ I ->sendPost ('/hello/John/Doe?query=value ' , ['foo ' => 'bar ' ]);
138140
139141 $ I ->seeResponseCodeIs (200 );
140142 $ response = json_decode ($ I ->grabResponse (), true );
@@ -164,10 +166,11 @@ public function convertPostJsonRequest(FunctionalTester $I): void
164166 // Check headers.
165167 $ I ->assertSame (
166168 [
167- 'User-Agent ' => ['Symfony BrowserKit ' ],
168- 'Content-Type ' => ['application/json ' ],
169- 'Cookie ' => ['name=value; name2=value2; name3=value3 ' ],
170- 'Host ' => ['localhost ' ],
169+ 'User-Agent ' => ['Symfony BrowserKit ' ],
170+ 'X-Default-Header ' => ['default-value ' ],
171+ 'Content-Type ' => ['application/json ' ],
172+ 'Cookie ' => ['name=value; name2=value2; name3=value3 ' ],
173+ 'Host ' => ['localhost ' ],
171174 ],
172175 $ response ['headers ' ],
173176 'Header parameters are not identical. '
@@ -187,4 +190,150 @@ public function convertPostJsonRequest(FunctionalTester $I): void
187190 // Check uploaded files.
188191 $ I ->assertSame ([], $ response ['uploaded_files ' ], 'Uploaded file parameters are not identical. ' );
189192 }
193+
194+ public function convertPutRequest (FunctionalTester $ I ): void
195+ {
196+ $ I ->haveHttpHeader ('Content-type ' , 'application/json ' );
197+
198+ $ I ->sendPut ('/echo ' , ['foo ' => 'bar ' ]);
199+
200+ $ I ->seeResponseCodeIs (200 );
201+ $ response = json_decode ($ I ->grabResponse (), true );
202+
203+ $ I ->assertSame ('PUT ' , $ response ['method ' ], 'Method is not identical. ' );
204+ $ I ->assertSame ('{"foo":"bar"} ' , $ response ['body ' ], 'Request body is not identical. ' );
205+ $ I ->assertSame (['foo ' => 'bar ' ], $ response ['parsed_body ' ], 'Parsed request body is not identical. ' );
206+ }
207+
208+ public function convertPatchRequest (FunctionalTester $ I ): void
209+ {
210+ $ I ->haveHttpHeader ('Content-type ' , 'application/json ' );
211+
212+ $ I ->sendPatch ('/echo ' , ['key ' => 'value ' ]);
213+
214+ $ I ->seeResponseCodeIs (200 );
215+ $ response = json_decode ($ I ->grabResponse (), true );
216+
217+ $ I ->assertSame ('PATCH ' , $ response ['method ' ], 'Method is not identical. ' );
218+ $ I ->assertSame ('{"key":"value"} ' , $ response ['body ' ], 'Request body is not identical. ' );
219+ $ I ->assertSame (['key ' => 'value ' ], $ response ['parsed_body ' ], 'Parsed request body is not identical. ' );
220+ }
221+
222+ public function convertDeleteRequest (FunctionalTester $ I ): void
223+ {
224+ $ I ->sendDelete ('/echo ' );
225+
226+ $ I ->seeResponseCodeIs (200 );
227+ $ response = json_decode ($ I ->grabResponse (), true );
228+
229+ $ I ->assertSame ('DELETE ' , $ response ['method ' ], 'Method is not identical. ' );
230+ }
231+
232+ public function convertPostWithFileUpload (FunctionalTester $ I ): void
233+ {
234+ $ tmpFile = tempnam (sys_get_temp_dir (), 'test_upload_ ' );
235+ file_put_contents ($ tmpFile , 'file content here ' );
236+
237+ $ I ->haveHttpHeader ('Content-type ' , 'multipart/form-data ' );
238+ $ I ->sendPost (
239+ '/upload ' ,
240+ [],
241+ [
242+ 'attachment ' => [
243+ 'tmp_name ' => $ tmpFile ,
244+ 'name ' => 'test.txt ' ,
245+ 'type ' => 'text/plain ' ,
246+ 'size ' => filesize ($ tmpFile ),
247+ 'error ' => UPLOAD_ERR_OK ,
248+ ],
249+ ]
250+ );
251+
252+ $ I ->seeResponseCodeIs (200 );
253+ $ response = json_decode ($ I ->grabResponse (), true );
254+
255+ $ I ->assertSame ('POST ' , $ response ['method ' ], 'Method is not identical. ' );
256+ $ I ->assertCount (1 , $ response ['uploaded_files ' ], 'Expected one uploaded file. ' );
257+ $ I ->assertSame ('test.txt ' , $ response ['uploaded_files ' ]['attachment ' ]['filename ' ]);
258+ $ I ->assertSame ('text/plain ' , $ response ['uploaded_files ' ]['attachment ' ]['media_type ' ]);
259+ $ I ->assertSame ('file content here ' , $ response ['uploaded_files ' ]['attachment ' ]['content ' ]);
260+ $ I ->assertSame (UPLOAD_ERR_OK , $ response ['uploaded_files ' ]['attachment ' ]['error ' ]);
261+
262+ @unlink ($ tmpFile );
263+ }
264+
265+ public function handleNon200StatusCode (FunctionalTester $ I ): void
266+ {
267+ $ I ->sendGet ('/status/404 ' );
268+
269+ $ I ->seeResponseCodeIs (404 );
270+ }
271+
272+ public function handleServerErrorStatusCode (FunctionalTester $ I ): void
273+ {
274+ $ I ->sendGet ('/status/500 ' );
275+
276+ $ I ->seeResponseCodeIs (500 );
277+ }
278+
279+ public function handleRedirectResponse (FunctionalTester $ I ): void
280+ {
281+ $ I ->stopFollowingRedirects ();
282+
283+ $ I ->sendGet ('/redirect ' );
284+
285+ $ I ->seeResponseCodeIs (302 );
286+ $ I ->seeHttpHeader ('Location ' , '/hello/John/Doe ' );
287+
288+ $ I ->startFollowingRedirects ();
289+ }
290+
291+ public function handleEmptyResponse (FunctionalTester $ I ): void
292+ {
293+ $ I ->sendGet ('/empty ' );
294+
295+ $ I ->seeResponseCodeIs (204 );
296+ $ I ->assertSame ('' , $ I ->grabResponse (), 'Response body should be empty. ' );
297+ }
298+
299+ public function convertMinimalGetRequest (FunctionalTester $ I ): void
300+ {
301+ $ I ->sendGet ('/echo ' );
302+
303+ $ I ->seeResponseCodeIs (200 );
304+ $ response = json_decode ($ I ->grabResponse (), true );
305+
306+ $ I ->assertSame ('GET ' , $ response ['method ' ], 'Method is not identical. ' );
307+ $ I ->assertSame ('http://localhost/echo ' , $ response ['uri ' ], 'Uri is not identical. ' );
308+ $ I ->assertSame ([], $ response ['query_params ' ], 'Query parameters should be empty. ' );
309+ $ I ->assertSame ([], $ response ['cookie_params ' ], 'Cookie parameters should be empty. ' );
310+ $ I ->assertNull ($ response ['parsed_body ' ], 'Parsed body should be null. ' );
311+ }
312+
313+ public function convertPostWithEmptyBody (FunctionalTester $ I ): void
314+ {
315+ $ I ->haveHttpHeader ('Content-type ' , 'application/json ' );
316+
317+ $ I ->sendPost ('/echo ' , '' );
318+
319+ $ I ->seeResponseCodeIs (200 );
320+ $ response = json_decode ($ I ->grabResponse (), true );
321+
322+ $ I ->assertSame ('POST ' , $ response ['method ' ], 'Method is not identical. ' );
323+ $ I ->assertSame ('' , $ response ['body ' ], 'Request body should be empty. ' );
324+ }
325+
326+ public function configHeadersAreSentWithEveryRequest (FunctionalTester $ I ): void
327+ {
328+ $ I ->sendGet ('/echo ' );
329+
330+ $ I ->seeResponseCodeIs (200 );
331+ $ response = json_decode ($ I ->grabResponse (), true );
332+
333+ $ I ->assertSame (
334+ 'default-value ' ,
335+ $ response ['headers ' ]['X-Default-Header ' ][0 ] ?? null ,
336+ 'Default header from config should be present. '
337+ );
338+ }
190339}
0 commit comments