diff --git a/src/Client.php b/src/Client.php index 5d5bb43797..6c559cf26d 100644 --- a/src/Client.php +++ b/src/Client.php @@ -113,6 +113,7 @@ class Client implements Stdlib\DispatchableInterface 'keepalive' => false, 'outputstream' => false, 'encodecookies' => true, + 'argseparator' => null, 'rfc3986strict' => false ); @@ -355,6 +356,33 @@ public function getMethod() return $this->getRequest()->getMethod(); } + /** + * Set the query string argument separator + * + * @param string $argSeparator + * @return Client + */ + public function setArgSeparator($argSeparator) + { + $this->setOptions(array("argseparator" => $argSeparator)); + return $this; + } + + /** + * Get the query string argument separator + * + * @return string + */ + public function getArgSeparator() + { + $argSeparator = $this->config['argseparator']; + if (empty($argSeparator)) { + $argSeparator = ini_get('arg_separator.output'); + $this->setArgSeparator($argSeparator); + } + return $argSeparator; + } + /** * Set the encoding type and the boundary (if any) * @@ -773,14 +801,14 @@ public function send(Request $request = null) if (!empty($queryArray)) { $newUri = $uri->toString(); - $queryString = http_build_query($query); + $queryString = http_build_query($query, null, $this->getArgSeparator()); if ($this->config['rfc3986strict']) { $queryString = str_replace('+', '%20', $queryString); } if (strpos($newUri, '?') !== false) { - $newUri .= '&' . $queryString; + $newUri .= $this->getArgSeparator() . $queryString; } else { $newUri .= '?' . $queryString; } diff --git a/test/Client/CommonHttpTests.php b/test/Client/CommonHttpTests.php index b75b7a5d09..df6a0fdf6a 100644 --- a/test/Client/CommonHttpTests.php +++ b/test/Client/CommonHttpTests.php @@ -113,20 +113,28 @@ protected function tearDown() * Simple request tests */ + public function methodProvider() + { + return array( + array(Request::METHOD_GET), + array(Request::METHOD_POST), + array(Request::METHOD_OPTIONS), + array(Request::METHOD_PUT), + array(Request::METHOD_DELETE), + array(Request::METHOD_PATCH), + ); + } + /** * Test simple requests * + * @dataProvider methodProvider */ - public function testSimpleRequests() + public function testSimpleRequests($method) { - $methods= array(Request::METHOD_GET, Request::METHOD_POST, Request::METHOD_OPTIONS, - Request::METHOD_PUT, Request::METHOD_DELETE, Request::METHOD_PATCH); - - foreach ($methods as $method) { - $this->client->setMethod($method); - $res = $this->client->send(); - $this->assertTrue($res->isSuccess(), "HTTP {$method} request failed."); - } + $this->client->setMethod($method); + $res = $this->client->send(); + $this->assertTrue($res->isSuccess(), "HTTP {$method} request failed."); } /** @@ -977,6 +985,21 @@ public function testContentTypeAdditionlInfo($params) $request->getHeaders()->get('Content-Type')->getFieldValue()); } + /** + * @group 2774 + * @group 2745 + */ + public function testUsesProvidedArgSeparator() + { + $this->client->setArgSeparator(';'); + $request = new Request(); + $request->setUri('http://framework.zend.com'); + $request->setQuery(array('foo' => 'bar', 'baz' => 'bat')); + $this->client->send($request); + $rawRequest = $this->client->getLastRawRequest(); + $this->assertContains('?foo=bar;baz=bat', $rawRequest); + } + /** * Internal helpder function to get the contents of test files * @@ -1045,5 +1068,4 @@ public static function invalidConfigProvider() array(55) ); } - } diff --git a/test/ClientTest.php b/test/ClientTest.php index ac1d939d98..0e48dbb77f 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -79,4 +79,26 @@ public function testIfArrayIteratorOfHeadersCanBeSet() $cookies = $client->getCookies(); $this->assertEquals(2, count($cookies)); } + + /** + * @group 2774 + * @group 2745 + */ + public function testArgSeparatorDefaultsToIniSetting() + { + $argSeparator = ini_get('arg_separator.output'); + $client = new Client(); + $this->assertEquals($argSeparator, $client->getArgSeparator()); + } + + /** + * @group 2774 + * @group 2745 + */ + public function testCanOverrideArgSeparator() + { + $client = new Client(); + $client->setArgSeparator(';'); + $this->assertEquals(';', $client->getArgSeparator()); + } }