From caefc4ff0bc9db9443402bffa9d02f3dfb267cb3 Mon Sep 17 00:00:00 2001 From: Benjamin Friedman Date: Thu, 20 Jul 2017 15:05:31 -0700 Subject: [PATCH 1/5] testing hhvm support --- src/Parse/ParsePolygon.php | 2 +- tests/Parse/ParseStreamHttpClientTest.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Parse/ParsePolygon.php b/src/Parse/ParsePolygon.php index f5582748..4eaf64ed 100755 --- a/src/Parse/ParsePolygon.php +++ b/src/Parse/ParsePolygon.php @@ -50,7 +50,7 @@ public function setCoordinates($coords) } $points = []; foreach ($coords as $coord) { - $geoPoint; + $geoPoint = null; if ($coord instanceof ParseGeoPoint) { $geoPoint = $coord; } elseif (is_array($coord) && count($coord) === 2) { diff --git a/tests/Parse/ParseStreamHttpClientTest.php b/tests/Parse/ParseStreamHttpClientTest.php index 9cd8eef5..061bcf70 100644 --- a/tests/Parse/ParseStreamHttpClientTest.php +++ b/tests/Parse/ParseStreamHttpClientTest.php @@ -14,6 +14,9 @@ class ParseStreamHttpClientTest extends \PHPUnit_Framework_TestCase { + /** + * @group test-get-response + */ public function testGetResponse() { $client = new ParseStreamHttpClient(); @@ -25,7 +28,7 @@ public function testGetResponse() // get response headers $headers = $client->getResponseHeaders(); - $this->assertEquals('HTTP/1.0 200 OK', $headers['http_code']); + $this->assertTrue(preg_match('|HTTP/1\.\d\s200\sOK|', $headers['http_code']) === 1); } public function testInvalidUrl() From 7578b371489107e17784d448f09db70afed823e7 Mon Sep 17 00:00:00 2001 From: Benjamin Friedman Date: Thu, 20 Jul 2017 15:08:29 -0700 Subject: [PATCH 2/5] Adds hhvm build --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 507e536d..956fdb9c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ php: - '5.6' - '7.0' - '7.1' -# - hhvm # on Trusty only + - hhvm # on Trusty only # - nightly cache: From f10bb373b1c0ac302c1d079938cb6fbfc96b5161 Mon Sep 17 00:00:00 2001 From: Benjamin Friedman Date: Thu, 20 Jul 2017 19:05:16 -0700 Subject: [PATCH 3/5] Added HHVM quirk fixes --- .travis.yml | 2 ++ .../HttpClients/ParseStreamHttpClient.php | 30 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 956fdb9c..87d7ed89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,8 @@ matrix: include: - php: '5.6' env: STREAM_CLIENT_ONLY=1 + - php: hhvm + env: STREAM_CLIENT_ONLY=1 before_install: - nvm install 6.11 diff --git a/src/Parse/HttpClients/ParseStreamHttpClient.php b/src/Parse/HttpClients/ParseStreamHttpClient.php index 4c9b29aa..6e5a6841 100644 --- a/src/Parse/HttpClients/ParseStreamHttpClient.php +++ b/src/Parse/HttpClients/ParseStreamHttpClient.php @@ -209,8 +209,17 @@ public function send($url, $method = 'GET', $data = array()) if ($method == "GET") { // handle GET $query = http_build_query($data, null, '&'); - $this->options['http']['content'] = $query; + + if (!defined('HHVM_VERSION')) { + $this->options['http']['content'] = $query; + } else { + // HHVM doesn't reapply 'content' to the url + // have to do it ourselves + $url.='?'.$query; + } + $this->addRequestHeader('Content-type', 'application/x-www-form-urlencoded'); + } elseif ($method == "POST") { // handle POST $this->options['http']['content'] = $data; @@ -221,7 +230,24 @@ public function send($url, $method = 'GET', $data = array()) } // set headers - $this->options['http']['header'] = $this->buildRequestHeaders(); + if (!defined('HHVM_VERSION')) { + // default + $this->options['http']['header'] = $this->buildRequestHeaders(); + } else { + /** + * HHVM bug bypass + * + * Passing via 'header' ends up duplicating all custom headers submitted due to a bug in HHVM. + * We can bypass this through the separate 'user_agent' field, as it is never sanitized, + * so we can append our desired headers after the initial user-agent string. + * Note that this works in php5 as well (probably 7 and up too), + * but for now we use this only where we need it. + * + * HHVM Code in Question: + * https://github.com/facebook/hhvm/blob/master/hphp/runtime/base/http-stream-wrapper.cpp#L92 + */ + $this->options['http']['user_agent'] = "parse-php-sdk\r\n".$this->buildRequestHeaders(); + } // create a stream context $this->parseStream->createContext($this->options); From fb3eed6c32e5f644bf578e3ae3c82412a719104b Mon Sep 17 00:00:00 2001 From: Benjamin Friedman Date: Thu, 20 Jul 2017 19:07:05 -0700 Subject: [PATCH 4/5] lint!! --- src/Parse/HttpClients/ParseStreamHttpClient.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Parse/HttpClients/ParseStreamHttpClient.php b/src/Parse/HttpClients/ParseStreamHttpClient.php index 6e5a6841..b4b01181 100644 --- a/src/Parse/HttpClients/ParseStreamHttpClient.php +++ b/src/Parse/HttpClients/ParseStreamHttpClient.php @@ -219,7 +219,6 @@ public function send($url, $method = 'GET', $data = array()) } $this->addRequestHeader('Content-type', 'application/x-www-form-urlencoded'); - } elseif ($method == "POST") { // handle POST $this->options['http']['content'] = $data; From b470f2deafc7e828b483e71fd93bd4026d40a8d2 Mon Sep 17 00:00:00 2001 From: Benjamin Friedman Date: Fri, 21 Jul 2017 08:48:42 -0700 Subject: [PATCH 5/5] Tightened up comment --- src/Parse/HttpClients/ParseStreamHttpClient.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Parse/HttpClients/ParseStreamHttpClient.php b/src/Parse/HttpClients/ParseStreamHttpClient.php index b4b01181..bda4e3e0 100644 --- a/src/Parse/HttpClients/ParseStreamHttpClient.php +++ b/src/Parse/HttpClients/ParseStreamHttpClient.php @@ -235,15 +235,12 @@ public function send($url, $method = 'GET', $data = array()) } else { /** * HHVM bug bypass - * * Passing via 'header' ends up duplicating all custom headers submitted due to a bug in HHVM. * We can bypass this through the separate 'user_agent' field, as it is never sanitized, * so we can append our desired headers after the initial user-agent string. * Note that this works in php5 as well (probably 7 and up too), * but for now we use this only where we need it. - * - * HHVM Code in Question: - * https://github.com/facebook/hhvm/blob/master/hphp/runtime/base/http-stream-wrapper.cpp#L92 + * Source: https://github.com/facebook/hhvm/blob/master/hphp/runtime/base/http-stream-wrapper.cpp#L92 */ $this->options['http']['user_agent'] = "parse-php-sdk\r\n".$this->buildRequestHeaders(); }