mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-09-04 14:56:26 +00:00
Merge pull request #180 from zachborboa/master
Fix missing body in DELETE tests
This commit is contained in:
@@ -95,9 +95,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
public function testGet()
|
||||
{
|
||||
$test = new Test();
|
||||
$this->assertEquals('GET', $test->server('server', 'GET', array(
|
||||
'key' => 'REQUEST_METHOD',
|
||||
)));
|
||||
$this->assertEquals('GET', $test->server('request_method', 'GET'));
|
||||
}
|
||||
|
||||
public function testUrl()
|
||||
@@ -155,7 +153,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
$curl->setHeader('X-DEBUG-TEST', 'delete_with_body');
|
||||
$curl->delete($data, array('wibble' => 'wubble'));
|
||||
$this->assertEquals(Test::TEST_URL, $curl->base_url);
|
||||
$this->assertEquals('{"get":{"key":"value"},"post":{"wibble":"wubble"}}', $curl->raw_response);
|
||||
$this->assertEquals('{"get":{"key":"value"},"delete":{"wibble":"wubble"}}', $curl->raw_response);
|
||||
|
||||
$curl = new Curl(Test::TEST_URL);
|
||||
$curl->setHeader('X-DEBUG-TEST', 'get');
|
||||
@@ -257,9 +255,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
public function testPostRequestMethod()
|
||||
{
|
||||
$test = new Test();
|
||||
$this->assertEquals('POST', $test->server('server', 'POST', array(
|
||||
'key' => 'REQUEST_METHOD',
|
||||
)));
|
||||
$this->assertEquals('POST', $test->server('request_method', 'POST'));
|
||||
}
|
||||
|
||||
public function testPostContinueResponseHeader()
|
||||
@@ -413,30 +409,23 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('PATCH', $test->server('request_method', 'PATCH'));
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
public function testDeleteRequestMethod()
|
||||
{
|
||||
$test = new Test();
|
||||
$this->assertEquals('DELETE', $test->server('server', 'DELETE', array(
|
||||
'key' => 'REQUEST_METHOD',
|
||||
)));
|
||||
|
||||
$test = new Test();
|
||||
$this->assertEquals('delete', $test->server('delete', 'DELETE', array(
|
||||
'test' => 'delete',
|
||||
'key' => 'test',
|
||||
)));
|
||||
$this->assertEquals('DELETE', $test->server('request_method', 'DELETE'));
|
||||
}
|
||||
|
||||
public function testDeleteRequestBody()
|
||||
{
|
||||
$test = new Test();
|
||||
$test->server('delete_with_body', 'DELETE', array('foo' => 'bar'), array('wibble' => 'wubble'));
|
||||
$this->assertEquals('{"get":{"foo":"bar"},"post":{"wibble":"wubble"}}', $test->curl->raw_response);
|
||||
$this->assertEquals('{"get":{"foo":"bar"},"delete":{"wibble":"wubble"}}', $test->curl->raw_response);
|
||||
}
|
||||
|
||||
public function testHeadRequestMethod()
|
||||
{
|
||||
$test = new Test();
|
||||
$test->server('request_method', 'HEAD', array(
|
||||
'key' => 'REQUEST_METHOD',
|
||||
));
|
||||
$test->server('request_method', 'HEAD');
|
||||
$this->assertEquals('HEAD', $test->curl->response_headers['X-REQUEST-METHOD']);
|
||||
$this->assertEmpty($test->curl->response);
|
||||
}
|
||||
@@ -444,9 +433,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
public function testOptionsRequestMethod()
|
||||
{
|
||||
$test = new Test();
|
||||
$test->server('request_method', 'OPTIONS', array(
|
||||
'key' => 'REQUEST_METHOD',
|
||||
));
|
||||
$test->server('request_method', 'OPTIONS');
|
||||
$this->assertEquals('OPTIONS', $test->curl->response_headers['X-REQUEST-METHOD']);
|
||||
}
|
||||
|
||||
@@ -476,9 +463,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(md5_file($upload_file_path), $download_test->curl->response_headers['ETag']);
|
||||
|
||||
// Ensure successive requests set the appropriate values.
|
||||
$this->assertEquals('GET', $download_test->server('server', 'GET', array(
|
||||
'key' => 'REQUEST_METHOD',
|
||||
)));
|
||||
$this->assertEquals('GET', $download_test->server('request_method', 'GET'));
|
||||
$this->assertFalse(is_bool($download_test->curl->response));
|
||||
$this->assertFalse(is_bool($download_test->curl->raw_response));
|
||||
|
||||
@@ -549,6 +534,12 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testDigestHttpAuth()
|
||||
{
|
||||
// Skip Digest Access Authentication test on HHVM.
|
||||
// https://github.com/facebook/hhvm/issues/5201
|
||||
if (defined('HHVM_VERSION')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$username = 'myusername';
|
||||
$password = 'mypassword';
|
||||
$invalid_password = 'anotherpassword';
|
||||
|
||||
@@ -1735,7 +1735,7 @@ class MultiCurlTest extends PHPUnit_Framework_TestCase
|
||||
$multi_curl->setHeader('X-DEBUG-TEST', 'delete_with_body');
|
||||
$multi_curl->addDelete($data, array('wibble' => 'wubble'))->complete(function($instance) {
|
||||
PHPUnit_Framework_Assert::assertEquals(Test::TEST_URL, $instance->base_url);
|
||||
PHPUnit_Framework_Assert::assertEquals('{"get":{"key":"value"},"post":{"wibble":"wubble"}}',
|
||||
PHPUnit_Framework_Assert::assertEquals('{"get":{"key":"value"},"delete":{"wibble":"wubble"}}',
|
||||
$instance->raw_response);
|
||||
});
|
||||
$multi_curl->start();
|
||||
|
||||
@@ -6,6 +6,7 @@ use \Helper\Test;
|
||||
$http_raw_post_data = file_get_contents('php://input');
|
||||
$_PUT = array();
|
||||
$_PATCH = array();
|
||||
$_DELETE = array();
|
||||
|
||||
$request_method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '';
|
||||
if (!array_key_exists('CONTENT_TYPE', $_SERVER) && array_key_exists('HTTP_CONTENT_TYPE', $_SERVER)) {
|
||||
@@ -25,6 +26,11 @@ if ($request_method === 'POST') {
|
||||
parse_str($http_raw_post_data, $_PATCH);
|
||||
$data_values = $_PATCH;
|
||||
}
|
||||
} elseif ($request_method === 'DELETE') {
|
||||
if (strpos($content_type, 'application/x-www-form-urlencoded') === 0) {
|
||||
parse_str($http_raw_post_data, $_DELETE);
|
||||
$data_values = $_DELETE;
|
||||
}
|
||||
}
|
||||
|
||||
$test = isset($_SERVER['HTTP_X_DEBUG_TEST']) ? $_SERVER['HTTP_X_DEBUG_TEST'] : '';
|
||||
@@ -227,7 +233,7 @@ if ($test == 'http_basic_auth') {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(array(
|
||||
'get' => $_GET,
|
||||
'post' => $_POST,
|
||||
'delete' => $_DELETE,
|
||||
));
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ find . -type "f" -iname "*.php" -exec php -l {} \;
|
||||
|
||||
# Run tests.
|
||||
cd tests && phpunit --configuration phpunit.xml
|
||||
if [[ "${?}" -ne 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Enforce line ending consistency in php files.
|
||||
crlf_file=$(find . -type "f" -iname "*.php" -exec grep --files-with-matches $'\r' {} \;)
|
||||
|
||||
Reference in New Issue
Block a user