Skip to content

Commit 3d6e9a5

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: Fix some redundant @return phpdoc [Dotenv][Runtime] Add $overrideExistingVars to bootEnv() and loadEnv() and dotenv_overload to SymfonyRuntime Add check and tests for public properties [BrowserKit][HttpClient][Routing] support building query strings with stringables
2 parents f95c06b + 714059c commit 3d6e9a5

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

HttpClientTrait.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,18 @@ private static function normalizeHeaders(array $headers): array
291291
private static function normalizeBody($body)
292292
{
293293
if (\is_array($body)) {
294-
return http_build_query($body, '', '&', \PHP_QUERY_RFC1738);
294+
array_walk_recursive($body, $caster = static function (&$v) use (&$caster) {
295+
if (\is_object($v)) {
296+
if ($vars = get_object_vars($v)) {
297+
array_walk_recursive($vars, $caster);
298+
$v = $vars;
299+
} elseif (method_exists($v, '__toString')) {
300+
$v = (string) $v;
301+
}
302+
}
303+
});
304+
305+
return http_build_query($body, '', '&');
295306
}
296307

297308
if (\is_string($body)) {

Tests/MockHttpClientTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,22 @@ public function testChangeResponseFactory()
400400

401401
$this->assertSame($expectedBody, $response->getContent());
402402
}
403+
404+
public function testStringableBodyParam()
405+
{
406+
$client = new MockHttpClient();
407+
408+
$param = new class() {
409+
public function __toString()
410+
{
411+
return 'bar';
412+
}
413+
};
414+
415+
$response = $client->request('GET', 'https://example.com', [
416+
'body' => ['foo' => $param],
417+
]);
418+
419+
$this->assertSame('foo=bar', $response->getRequestOptions()['body']);
420+
}
403421
}

0 commit comments

Comments
 (0)