@@ -26,6 +26,8 @@ public function iDoARequestOn(string $requestType, string $url)
2626 }
2727
2828 /**
29+ * by adding a parameter starting with "$_FILES.", it is possible to upload files
30+ *
2931 * @Given I do a :requestType request on :url with parameters
3032 */
3133 public function iDoARequestOnWithParameters (string $ requestType , string $ url , TableNode $ parameters )
@@ -41,13 +43,21 @@ public function iDoARequestOnWithParameters(string $requestType, string $url, Ta
4143 throw new \Exception ('Request type " ' . $ requestType . '" not yet implemented ' , 1693489230 );
4244 }
4345
44- $ parameterArray = [];
46+ $ files = [];
4547 foreach ($ parameters ->getRows () as $ index => $ row ) {
46- $ row [1 ] = $ this ->convertStringToValue ($ row [1 ]);
47- $ parameterArray [$ row [0 ]] = $ row [1 ];
48+ if (strncmp ($ row [0 ], '$_FILES. ' , strlen ('$_FILES. ' )) === 0 ) {
49+ $ row [0 ] = substr ($ row [0 ], strlen ('$_FILES. ' ));
50+ $ files [] = [$ row [0 ] => $ row [1 ]];
51+
52+ } else {
53+ $ row [1 ] = $ this ->convertStringToValue ($ row [1 ]);
54+ $ parameterArray [$ row [0 ]] = $ row [1 ];
55+ }
4856 }
49-
50- $ this ->send ($ requestType , $ url , $ parameterArray );
57+ if (count ($ files ) > 0 ) {
58+ $ this ->deleteHeader ('Content-Type ' );
59+ }
60+ $ this ->send ($ requestType , $ url , $ parameterArray , $ files );
5161 }
5262
5363 /**
0 commit comments