Skip to content

Commit

Permalink
Merge pull request #558 from zachborboa/master
Browse files Browse the repository at this point in the history
Add tests for content-length with DELETE requests
  • Loading branch information
zachborboa committed Nov 30, 2018
2 parents 1e70527 + bf68fc3 commit 9edf511
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Curl/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ public function delete($url, $query_parameters = array(), $data = array())

$this->setUrl($url, $query_parameters);
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'DELETE');
$this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data));
if (!empty($data)) {
$this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data));
}
return $this->exec();
}

Expand Down
16 changes: 16 additions & 0 deletions tests/PHPCurlClass/PHPCurlClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,22 @@ public function testDeleteRequestBody()
$this->assertEquals('{"get":{"foo":"bar"},"delete":{"wibble":"wubble"}}', $test->curl->rawResponse);
}

public function testDeleteContentLengthSetWithBody()
{
$request_body = 'a=1&b=2&c=3';
$test = new Test();
$test->server('request_method', 'DELETE', array(), $request_body);
$this->assertEquals(strlen($request_body), $test->curl->requestHeaders['content-length']);
}

public function testDeleteContentLengthUnsetWithoutBody()
{
$request_body = array();
$test = new Test();
$test->server('request_method', 'DELETE', array(), $request_body);
$this->assertFalse(isset($test->curl->requestHeaders['content-length']));
}

public function testHeadRequestMethod()
{
$test = new Test();
Expand Down

0 comments on commit 9edf511

Please sign in to comment.