Merge pull request #512 from zachborboa/master

Use correct body in POST requests that use empty arrays for data
This commit is contained in:
Zach Borboa
2018-04-26 03:22:57 -07:00
committed by GitHub
5 changed files with 33 additions and 6 deletions
+1 -1
View File
@@ -583,7 +583,7 @@ class Curl
* [2] https://github.com/php/php-src/pull/531
* [3] http://php.net/ChangeLog-5.php#5.5.11
*/
public function post($url, $data = array(), $follow_303_with_post = false)
public function post($url, $data = '', $follow_303_with_post = false)
{
if (is_array($url)) {
$follow_303_with_post = (bool)$data;
+1 -1
View File
@@ -209,7 +209,7 @@ class MultiCurl
*
* @return object
*/
public function addPost($url, $data = array(), $follow_303_with_post = false)
public function addPost($url, $data = '', $follow_303_with_post = false)
{
if (is_array($url)) {
$follow_303_with_post = (bool)$data;
+6 -4
View File
@@ -16,14 +16,16 @@ class Test
$this->curl->setOpt(CURLOPT_SSL_VERIFYHOST, false);
}
public function server($test, $request_method, $query_parameters = array(), $data = array())
public function server($test, $request_method, $arg1 = null, $arg2 = null)
{
$this->curl->setHeader('X-DEBUG-TEST', $test);
$request_method = strtolower($request_method);
if (is_array($data) && empty($data)) {
$this->curl->$request_method(self::TEST_URL, $query_parameters);
if ($arg1 !== null && $arg2 !== null) {
$this->curl->$request_method(self::TEST_URL, $arg1, $arg2);
} elseif ($arg1 !== null) {
$this->curl->$request_method(self::TEST_URL, $arg1);
} else {
$this->curl->$request_method(self::TEST_URL, $query_parameters, $data);
$this->curl->$request_method(self::TEST_URL);
}
return $this->curl->response;
}
+9
View File
@@ -294,6 +294,15 @@ class CurlTest extends \PHPUnit\Framework\TestCase
)));
}
public function testPostDataEmptyJson()
{
$test = new Test();
$test->curl->setHeader('Content-Type', 'application/json');
$test->server('post_json', 'POST');
$this->assertEquals('', $test->curl->response);
$this->assertEquals('', $test->curl->getOpt(CURLOPT_POSTFIELDS));
}
public function testPostAssociativeArrayData()
{
$data = array(
@@ -2852,4 +2852,20 @@ class MultiCurlTest extends \PHPUnit\Framework\TestCase
$this->assertEquals($expect_retries, $instance->retries);
}
}
public function testPostDataEmptyJson()
{
$multi_curl = new MultiCurl();
$multi_curl->setHeader('X-DEBUG-TEST', 'post_json');
$multi_curl->setHeader('Content-Type', 'application/json');
$multi_curl->addPost(Test::TEST_URL);
$post_complete_called = false;
$multi_curl->complete(function ($instance) use (&$post_complete_called) {
\PHPUnit\Framework\Assert::assertEquals('', $instance->response);
\PHPUnit\Framework\Assert::assertEquals('', $instance->getOpt(CURLOPT_POSTFIELDS));
$post_complete_called = true;
});
$multi_curl->start();
$this->assertTrue($post_complete_called);
}
}