Merge pull request #235 from petewatts/master

Fix #234 PATCH request method support data body
This commit is contained in:
Zach Borboa
2015-08-21 15:32:30 -07:00
3 changed files with 22 additions and 5 deletions
+5 -4
View File
@@ -441,6 +441,11 @@ class Curl
$data = $url;
$url = $this->baseUrl;
}
if (is_array($data) && empty($data)) {
$this->unsetHeader('Content-Length');
}
$this->setURL($url);
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'PATCH');
$this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data));
@@ -463,10 +468,6 @@ class Curl
$url = $this->baseUrl;
}
if (is_array($data) && empty($data)) {
$this->unsetHeader('Content-Length');
}
$this->setURL($url);
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'POST');
$this->setOpt(CURLOPT_POST, true);
+14 -1
View File
@@ -82,7 +82,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
public function testUserAgent()
{
$php_version = 'PHP\/' . PHP_VERSION;
$php_version = preg_replace('/([\.\+\?\*\(\)\[\]\^\$\/])/', '\\\\\1', 'PHP/' . PHP_VERSION);
$curl_version = curl_version();
$curl_version = 'curl\/' . $curl_version['version'];
@@ -409,6 +409,19 @@ class CurlTest extends PHPUnit_Framework_TestCase
$this->assertEquals('PATCH', $test->server('request_method', 'PATCH'));
}
public function testPatchData()
{
$test = new Test();
$this->assertEquals('key=value', $test->server('patch', 'PATCH', array(
'key' => 'value',
)));
$test = new Test();
$this->assertEquals('{"key":"value"}', $test->server('patch', 'PATCH', json_encode(array(
'key' => 'value',
))));
}
public function testPatchRequestMethodWithMultidimArray()
{
$data = array(
+3
View File
@@ -107,6 +107,9 @@ if ($test == 'http_basic_auth') {
} elseif ($test === 'put') {
echo $http_raw_post_data;
exit;
} elseif ($test === 'patch') {
echo $http_raw_post_data;
exit;
} elseif ($test === 'post_multidimensional') {
echo $http_raw_post_data;
exit;