Skip to content

Commit 293a010

Browse files
authored
Merge pull request #56 from Codeception/delete-sends-body
DELETE method sends request body
2 parents 2cd9901 + 608bc27 commit 293a010

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

src/Codeception/Module/REST.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
*/
8484
class REST extends CodeceptionModule implements DependsOnModule, PartedModule, API, ConflictsWithModule
8585
{
86-
const QUERY_PARAMS_AWARE_METHODS = ['GET', 'HEAD', 'DELETE', 'OPTIONS'];
86+
const QUERY_PARAMS_AWARE_METHODS = ['GET', 'HEAD', 'OPTIONS'];
8787

8888
protected $config = [
8989
'url' => '',

tests/unit/Codeception/Module/RestTest.php

+53-2
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)