diff --git a/.travis.yml b/.travis.yml index 507e536d..87d7ed89 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: @@ -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..bda4e3e0 100644 --- a/src/Parse/HttpClients/ParseStreamHttpClient.php +++ b/src/Parse/HttpClients/ParseStreamHttpClient.php @@ -209,7 +209,15 @@ 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 @@ -221,7 +229,21 @@ 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. + * 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(); + } // create a stream context $this->parseStream->createContext($this->options); 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()