8000 [HttpClient] Fix overriding default options with null · symfony/symfony@37ac416 · GitHub
[go: up one dir, main page]

Skip to content

Commit 37ac416

Browse files
[HttpClient] Fix overriding default options with null
1 parent 46408f0 commit 37ac416

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/Symfony/Component/HttpClient/HttpClientTrait.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,7 @@ private static function mergeDefaultOptions(array $options, array $defaultOption
187187
// Option "query" is never inherited from defaults
188188
$options['query'] = $options['query'] ?? [];
189189

190-
foreach ($defaultOptions as $k => $v) {
191-
if ('normalized_headers' !== $k && !isset($options[$k])) {
192-
$options[$k] = $v;
193-
}
194-
}
190+
$options += $defaultOptions;
195191

196192
if (isset($defaultOptions['extra'])) {
197193
$options['extra'] += $defaultOptions['extra'];

src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\HttpClient\Chunk\DataChunk;
1515
use Symfony\Component\HttpClient\Chunk\ErrorChunk;
1616
use Symfony\Component\HttpClient\Chunk\FirstChunk;
17+
use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
1718
use Symfony\Component\HttpClient\Exception\TransportException;
1819
use Symfony\Component\HttpClient\MockHttpClient;
1920
use Symfony\Component\HttpClient\NativeHttpClient;
@@ -150,6 +151,15 @@ public function testThrowExceptionInBodyGenerator()
150151
$this->assertSame('bar ccc', $chunks[2]->getError());
151152
}
152153

154+
public function testMergeDefaultOptions()
155+
{
156+
$mockHttpClient = new MockHttpClient(null, 'https://example.com');
157+
158+
$this->expectException(InvalidArgumentException::class);
159+
$this->expectExceptionMessage('Invalid URL: scheme is missing');
160+
$mockHttpClient->request('GET', '/foo', ['base_uri' => null]);
161+
}
162+
153163
protected function getHttpClient(string $testCase): HttpClientInterface
154164
{
155165
$responses = [];

0 commit comments

Comments
 (0)
0