Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

File tree

3 files changed

+84
-12
lines changed

3 files changed

+84
-12
lines changed

src/Client.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class Client implements Stdlib\DispatchableInterface
113113
'keepalive' => false,
114114
'outputstream' => false,
115115
'encodecookies' => true,
116+
'argseparator' => null,
116117
'rfc3986strict' => false
117118
);
118119

@@ -355,6 +356,33 @@ public function getMethod()
355356
return $this->getRequest()->getMethod();
356357
}
357358

359+
/**
360+
* Set the query string argument separator
361+
*
362+
* @param string $argSeparator
363+
* @return Client
364+
*/
365+
public function setArgSeparator($argSeparator)
366+
{
367+
$this->setOptions(array("argseparator" => $argSeparator));
368+
return $this;
369+
}
370+
371+
/**
372+
* Get the query string argument separator
373+
*
374+
* @return string
375+
*/
376+
public function getArgSeparator()
377+
{
378+
$argSeparator = $this->config['argseparator'];
379+
if (empty($argSeparator)) {
380+
$argSeparator = ini_get('arg_separator.output');
381+
$this->setArgSeparator($argSeparator);
382+
}
383+
return $argSeparator;
384+
}
385+
358386
/**
359387
* Set the encoding type and the boundary (if any)
360388
*
@@ -773,14 +801,14 @@ public function send(Request $request = null)
773801

774802
if (!empty($queryArray)) {
775803
$newUri = $uri->toString();
776-
$queryString = http_build_query($query);
804+
$queryString = http_build_query($query, null, $this->getArgSeparator());
777805

778806
if ($this->config['rfc3986strict']) {
779807
$queryString = str_replace('+', '%20', $queryString);
780808
}
781809

782810
if (strpos($newUri, '?') !== false) {
783-
$newUri .= '&' . $queryString;
811+
$newUri .= $this->getArgSeparator() . $queryString;
784812
} else {
785813
$newUri .= '?' . $queryString;
786814
}

test/Client/CommonHttpTests.php

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,28 @@ protected function tearDown()
113113
* Simple request tests
114114
*/
115115

116+
public function methodProvider()
117+
{
118+
return array(
119+
array(Request::METHOD_GET),
120+
array(Request::METHOD_POST),
121+
array(Request::METHOD_OPTIONS),
122+
array(Request::METHOD_PUT),
123+
array(Request::METHOD_DELETE),
124+
array(Request::METHOD_PATCH),
125+
);
126+
}
127+
116128
/**
117129
* Test simple requests
118130
*
131+
* @dataProvider methodProvider
119132
*/
120-
public function testSimpleRequests()
133+
public function testSimpleRequests($method)
121134
{
122-
$methods= array(Request::METHOD_GET, Request::METHOD_POST, Request::METHOD_OPTIONS,
123-
Request::METHOD_PUT, Request::METHOD_DELETE, Request::METHOD_PATCH);
124-
125-
foreach ($methods as $method) {
126-
$this->client->setMethod($method);
127-
$res = $this->client->send();
128-
$this->assertTrue($res->isSuccess(), "HTTP {$method} request failed.");
129-
}
135+
$this->client->setMethod($method);
136+
$res = $this->client->send();
137+
$this->assertTrue($res->isSuccess(), "HTTP {$method} request failed.");
130138
}
131139

132140
/**
@@ -977,6 +985,21 @@ public function testContentTypeAdditionlInfo($params)
977985
$request->getHeaders()->get('Content-Type')->getFieldValue());
978986
}
979987

988+
/**
989+
* @group 2774
990+
* @group 2745
991+
*/
992+
public function testUsesProvidedArgSeparator()
993+
{
994+
$this->client->setArgSeparator(';');
995+
$request = new Request();
996+
$request->setUri('http://framework.zend.com');
997+
$request->setQuery(array('foo' => 'bar', 'baz' => 'bat'));
998+
$this->client->send($request);
999+
$rawRequest = $this->client->getLastRawRequest();
1000+
$this->assertContains('?foo=bar;baz=bat', $rawRequest);
1001+
}
1002+
9801003
/**
9811004
* Internal helpder function to get the contents of test files
9821005
*
@@ -1045,5 +1068,4 @@ public static function invalidConfigProvider()
10451068
array(55)
10461069
);
10471070
}
1048-
10491071
}

test/ClientTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,26 @@ public function testIfArrayIteratorOfHeadersCanBeSet()
7979
$cookies = $client->getCookies();
8080
$this->assertEquals(2, count($cookies));
8181
}
82+
83+
/**
84+
* @group 2774
85+
* @group 2745
86+
*/
87+
public function testArgSeparatorDefaultsToIniSetting()
88+
{
89+
$argSeparator = ini_get('arg_separator.output');
90+
$client = new Client();
91+
$this->assertEquals($argSeparator, $client->getArgSeparator());
92+
}
93+
94+
/**
95+
* @group 2774
96+
* @group 2745
97+
*/
98+
public function testCanOverrideArgSeparator()
99+
{
100+
$client = new Client();
101+
$client->setArgSeparator(';');
102+
$this->assertEquals(';', $client->getArgSeparator());
103+
}
82104
}

0 commit comments

Comments
 (0)