Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 18 additions & 27 deletions tests/PHPCurlClass/PHPCurlClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ public function testUserAgent()
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()
Expand Down Expand Up @@ -155,7 +153,7 @@ public function testSetUrlInConstructor()
$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');
Expand Down Expand Up @@ -257,9 +255,7 @@ public function testSetUrl()
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()
Expand Down Expand Up @@ -413,40 +409,31 @@ public function testPatchRequestMethod()
$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);
}

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']);
}

Expand Down Expand Up @@ -476,9 +463,7 @@ public function testDownload()
$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));

Expand Down Expand Up @@ -549,6 +534,12 @@ public function testBasicHttpAuth()

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';
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPCurlClass/PHPMultiCurlClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@ public function testSetUrlInConstructor()
$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();
Expand Down
8 changes: 7 additions & 1 deletion tests/PHPCurlClass/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
$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)) {
Expand All @@ -25,6 +26,11 @@
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'] : '';
Expand Down Expand Up @@ -227,7 +233,7 @@
header('Content-Type: application/json');
echo json_encode(array(
'get' => $_GET,
'post' => $_POST,
'delete' => $_DELETE,
));
exit;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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' {} \;)
Expand Down