From 7256a716a12af548ff5e67c0cbd6c2dadbf58f85 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Thu, 23 Apr 2015 15:44:15 -0700 Subject: [PATCH 1/4] Fix missing body in DELETE tests --- tests/PHPCurlClass/PHPCurlClassTest.php | 4 ++-- tests/PHPCurlClass/PHPMultiCurlClassTest.php | 2 +- tests/PHPCurlClass/server.php | 8 +++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index 1828003bb5..ec9da0cf0f 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -155,7 +155,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'); @@ -428,7 +428,7 @@ public function testDelete() $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() diff --git a/tests/PHPCurlClass/PHPMultiCurlClassTest.php b/tests/PHPCurlClass/PHPMultiCurlClassTest.php index f7c6430974..f82a9bac94 100644 --- a/tests/PHPCurlClass/PHPMultiCurlClassTest.php +++ b/tests/PHPCurlClass/PHPMultiCurlClassTest.php @@ -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(); diff --git a/tests/PHPCurlClass/server.php b/tests/PHPCurlClass/server.php index a25f54470a..0fe6f218f8 100644 --- a/tests/PHPCurlClass/server.php +++ b/tests/PHPCurlClass/server.php @@ -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)) { @@ -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'] : ''; @@ -227,7 +233,7 @@ header('Content-Type: application/json'); echo json_encode(array( 'get' => $_GET, - 'post' => $_POST, + 'delete' => $_DELETE, )); exit; } From 3ebc19f9162c4c50d52f7c3bc44da9447ff11650 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Thu, 23 Apr 2015 15:45:34 -0700 Subject: [PATCH 2/4] Clean up request method tests --- tests/PHPCurlClass/PHPCurlClassTest.php | 35 +++++++------------------ 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index ec9da0cf0f..e15a86f918 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -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() @@ -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() @@ -413,19 +409,14 @@ 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"},"delete":{"wibble":"wubble"}}', $test->curl->raw_response); @@ -434,9 +425,7 @@ public function testDelete() 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 @@ public function testHeadRequestMethod() 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 @@ 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)); From bfb932dc304b20173720b83f98b9edfd512900e1 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Thu, 23 Apr 2015 15:48:26 -0700 Subject: [PATCH 3/4] Fix script.sh exiting with return code 0 when phpunit tests fail --- tests/script.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/script.sh b/tests/script.sh index e9adb35fb1..1736e574d5 100755 --- a/tests/script.sh +++ b/tests/script.sh @@ -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' {} \;) From 8ce0a208b5984073541e953d1b8464e1e7719241 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Thu, 23 Apr 2015 16:19:47 -0700 Subject: [PATCH 4/4] Skip Digest Access Authentication test on HHVM --- tests/PHPCurlClass/PHPCurlClassTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index e15a86f918..5055751248 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -534,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';