@@ -162,7 +162,8 @@ public function testInitUrlSameAsBaseDirectory()
162
162
'url ' => '/vagrant/public/flightphp ' ,
163
163
'base ' => '/vagrant/public ' ,
164
164
'query ' => new Collection (),
165
- 'type ' => ''
165
+ 'type ' => '' ,
166
+ 'method ' => 'GET '
166
167
]);
167
168
$ this ->assertEquals ('/flightphp ' , $ request ->url );
168
169
}
@@ -172,7 +173,8 @@ public function testInitNoUrl()
172
173
$ request = new Request ([
173
174
'url ' => '' ,
174
175
'base ' => '/vagrant/public ' ,
175
- 'type ' => ''
176
+ 'type ' => '' ,
177
+ 'method ' => 'GET '
176
178
]);
177
179
$ this ->assertEquals ('/ ' , $ request ->url );
178
180
}
@@ -183,20 +185,43 @@ public function testInitWithJsonBody()
183
185
$ tmpfile = tmpfile ();
184
186
$ stream_path = stream_get_meta_data ($ tmpfile )['uri ' ];
185
187
file_put_contents ($ stream_path , '{"foo":"bar"} ' );
186
- $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
187
188
$ request = new Request ([
188
189
'url ' => '/something/fancy ' ,
189
190
'base ' => '/vagrant/public ' ,
190
191
'type ' => 'application/json ' ,
191
192
'length ' => 13 ,
192
193
'data ' => new Collection (),
193
194
'query ' => new Collection (),
194
- 'stream_path ' => $ stream_path
195
+ 'stream_path ' => $ stream_path ,
196
+ 'method ' => 'POST '
195
197
]);
196
198
$ this ->assertEquals ([ 'foo ' => 'bar ' ], $ request ->data ->getData ());
197
199
$ this ->assertEquals ('{"foo":"bar"} ' , $ request ->getBody ());
198
200
}
199
201
202
+ public function testInitWithFormBody ()
203
+ {
204
+ // create dummy file to pull request body from
205
+ $ tmpfile = tmpfile ();
206
+ $ stream_path = stream_get_meta_data ($ tmpfile )['uri ' ];
207
+ file_put_contents ($ stream_path , 'foo=bar&baz=qux ' );
208
+ $ request = new Request ([
209
+ 'url ' => '/something/fancy ' ,
210
+ 'base ' => '/vagrant/public ' ,
211
+ 'type ' => 'application/x-www-form-urlencoded ' ,
212
+ 'length ' => 15 ,
213
+ 'data ' => new Collection (),
214
+ 'query ' => new Collection (),
215
+ 'stream_path ' => $ stream_path ,
216
+ 'method ' => 'PATCH '
217
+ ]);
218
+ $ this ->assertEquals ([
219
+ 'foo ' => 'bar ' ,
220
+ 'baz ' => 'qux '
221
+ ], $ request ->data ->getData ());
222
+ $ this ->assertEquals ('foo=bar&baz=qux ' , $ request ->getBody ());
223
+ }
224
+
200
225
public function testGetHeader ()
201
226
{
202
227
$ _SERVER ['HTTP_X_CUSTOM_HEADER ' ] = 'custom header value ' ;
0 commit comments