Skip to content

Commit b33c23f

Browse files
committed
Merge pull request php-curl-class#180 from zachborboa/master
Fix missing body in DELETE tests
2 parents 29a1047 + 8ce0a20 commit b33c23f

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ public function testUserAgent()
9595
public function testGet()
9696
{
9797
$test = new Test();
98-
$this->assertEquals('GET', $test->server('server', 'GET', array(
99-
'key' => 'REQUEST_METHOD',
100-
)));
98+
$this->assertEquals('GET', $test->server('request_method', 'GET'));
10199
}
102100

103101
public function testUrl()
@@ -155,7 +153,7 @@ public function testSetUrlInConstructor()
155153
$curl->setHeader('X-DEBUG-TEST', 'delete_with_body');
156154
$curl->delete($data, array('wibble' => 'wubble'));
157155
$this->assertEquals(Test::TEST_URL, $curl->base_url);
158-
$this->assertEquals('{"get":{"key":"value"},"post":{"wibble":"wubble"}}', $curl->raw_response);
156+
$this->assertEquals('{"get":{"key":"value"},"delete":{"wibble":"wubble"}}', $curl->raw_response);
159157

160158
$curl = new Curl(Test::TEST_URL);
161159
$curl->setHeader('X-DEBUG-TEST', 'get');
@@ -257,9 +255,7 @@ public function testSetUrl()
257255
public function testPostRequestMethod()
258256
{
259257
$test = new Test();
260-
$this->assertEquals('POST', $test->server('server', 'POST', array(
261-
'key' => 'REQUEST_METHOD',
262-
)));
258+
$this->assertEquals('POST', $test->server('request_method', 'POST'));
263259
}
264260

265261
public function testPostContinueResponseHeader()
@@ -413,40 +409,31 @@ public function testPatchRequestMethod()
413409
$this->assertEquals('PATCH', $test->server('request_method', 'PATCH'));
414410
}
415411

416-
public function testDelete()
412+
public function testDeleteRequestMethod()
417413
{
418414
$test = new Test();
419-
$this->assertEquals('DELETE', $test->server('server', 'DELETE', array(
420-
'key' => 'REQUEST_METHOD',
421-
)));
422-
423-
$test = new Test();
424-
$this->assertEquals('delete', $test->server('delete', 'DELETE', array(
425-
'test' => 'delete',
426-
'key' => 'test',
427-
)));
415+
$this->assertEquals('DELETE', $test->server('request_method', 'DELETE'));
416+
}
428417

418+
public function testDeleteRequestBody()
419+
{
429420
$test = new Test();
430421
$test->server('delete_with_body', 'DELETE', array('foo' => 'bar'), array('wibble' => 'wubble'));
431-
$this->assertEquals('{"get":{"foo":"bar"},"post":{"wibble":"wubble"}}', $test->curl->raw_response);
422+
$this->assertEquals('{"get":{"foo":"bar"},"delete":{"wibble":"wubble"}}', $test->curl->raw_response);
432423
}
433424

434425
public function testHeadRequestMethod()
435426
{
436427
$test = new Test();
437-
$test->server('request_method', 'HEAD', array(
438-
'key' => 'REQUEST_METHOD',
439-
));
428+
$test->server('request_method', 'HEAD');
440429
$this->assertEquals('HEAD', $test->curl->response_headers['X-REQUEST-METHOD']);
441430
$this->assertEmpty($test->curl->response);
442431
}
443432

444433
public function testOptionsRequestMethod()
445434
{
446435
$test = new Test();
447-
$test->server('request_method', 'OPTIONS', array(
448-
'key' => 'REQUEST_METHOD',
449-
));
436+
$test->server('request_method', 'OPTIONS');
450437
$this->assertEquals('OPTIONS', $test->curl->response_headers['X-REQUEST-METHOD']);
451438
}
452439

@@ -476,9 +463,7 @@ public function testDownload()
476463
$this->assertEquals(md5_file($upload_file_path), $download_test->curl->response_headers['ETag']);
477464

478465
// Ensure successive requests set the appropriate values.
479-
$this->assertEquals('GET', $download_test->server('server', 'GET', array(
480-
'key' => 'REQUEST_METHOD',
481-
)));
466+
$this->assertEquals('GET', $download_test->server('request_method', 'GET'));
482467
$this->assertFalse(is_bool($download_test->curl->response));
483468
$this->assertFalse(is_bool($download_test->curl->raw_response));
484469

@@ -549,6 +534,12 @@ public function testBasicHttpAuth()
549534

550535
public function testDigestHttpAuth()
551536
{
537+
// Skip Digest Access Authentication test on HHVM.
538+
// https://github.com/facebook/hhvm/issues/5201
539+
if (defined('HHVM_VERSION')) {
540+
return;
541+
}
542+
552543
$username = 'myusername';
553544
$password = 'mypassword';
554545
$invalid_password = 'anotherpassword';

tests/PHPCurlClass/PHPMultiCurlClassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,7 @@ public function testSetUrlInConstructor()
17351735
$multi_curl->setHeader('X-DEBUG-TEST', 'delete_with_body');
17361736
$multi_curl->addDelete($data, array('wibble' => 'wubble'))->complete(function($instance) {
17371737
PHPUnit_Framework_Assert::assertEquals(Test::TEST_URL, $instance->base_url);
1738-
PHPUnit_Framework_Assert::assertEquals('{"get":{"key":"value"},"post":{"wibble":"wubble"}}',
1738+
PHPUnit_Framework_Assert::assertEquals('{"get":{"key":"value"},"delete":{"wibble":"wubble"}}',
17391739
$instance->raw_response);
17401740
});
17411741
$multi_curl->start();

tests/PHPCurlClass/server.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
$http_raw_post_data = file_get_contents('php://input');
77
$_PUT = array();
88
$_PATCH = array();
9+
$_DELETE = array();
910

1011
$request_method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '';
1112
if (!array_key_exists('CONTENT_TYPE', $_SERVER) && array_key_exists('HTTP_CONTENT_TYPE', $_SERVER)) {
@@ -25,6 +26,11 @@
2526
parse_str($http_raw_post_data, $_PATCH);
2627
$data_values = $_PATCH;
2728
}
29+
} elseif ($request_method === 'DELETE') {
30+
if (strpos($content_type, 'application/x-www-form-urlencoded') === 0) {
31+
parse_str($http_raw_post_data, $_DELETE);
32+
$data_values = $_DELETE;
33+
}
2834
}
2935

3036
$test = isset($_SERVER['HTTP_X_DEBUG_TEST']) ? $_SERVER['HTTP_X_DEBUG_TEST'] : '';
@@ -227,7 +233,7 @@
227233
header('Content-Type: application/json');
228234
echo json_encode(array(
229235
'get' => $_GET,
230-
'post' => $_POST,
236+
'delete' => $_DELETE,
231237
));
232238
exit;
233239
}

tests/script.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ find . -type "f" -iname "*.php" -exec php -l {} \;
33

44
# Run tests.
55
cd tests && phpunit --configuration phpunit.xml
6+
if [[ "${?}" -ne 0 ]]; then
7+
exit 1
8+
fi
69

710
# Enforce line ending consistency in php files.
811
crlf_file=$(find . -type "f" -iname "*.php" -exec grep --files-with-matches $'\r' {} \;)

0 commit comments

Comments
 (0)