8000 [HttpClient] Fix scoped client without query option configuration · symfony/symfony@907045a · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 907045a

Browse files
committed
[HttpClient] Fix scoped client without query option configuration
1 parent f72dd9c commit 907045a

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode)
14821482
->thenInvalid('Either "scope" or "base_uri" should be defined.')
14831483
->end()
14841484
->validate()
1485-
->ifTrue(function ($v) { return isset($v['query']) && !isset($v['base_uri']); })
1485+
->ifTrue(function ($v) { return !empty($v['query']) && !isset($v['base_uri']); })
14861486
->thenInvalid('"query" applies to "base_uri" but no base URI is defined.')
14871487
->end()
14881488
->children()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'http_client' => [
5+
'scoped_clients' => [
6+
'foo' => [
7+
'scope' => '.*',
8+
],
9+
],
10+
],
11+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:http-client>
10+
<framework:scoped-client
11+
name="foo"
12+
scope=".*"
13+
/>
14+
</framework:http-client>
15+
</framework:config>
16+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
framework:
2+
http_client:
3+
scoped_clients:
4+
foo:
5+
scope: '.*'

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,15 @@ public function testHttpClientDefaultOptions()
15471547
$this->assertSame(ScopingHttpClient::class, $container->getDefinition('foo')->getClass());
15481548
}
15491549

1550+
public function testScopedHttpClientWithoutQueryOption()
1551+
{
1552+
$container = $this->createContainerFromFile('http_client_scoped_without_query_option');
1553+
$this->assertTrue($container->hasDefinition('http_client'), '->registerHttpClientConfiguration() loads http_client.xml');
1554+
1555+
$this->assertTrue($container->hasDefinition('foo'), 'should have the "foo" service.');
1556+
$this->assertSame(ScopingHttpClient::class, $container->getDefinition('foo')->getClass());
1557+
}
1558+
15501559
public function testHttpClientOverrideDefaultOptions()
15511560
{
15521561
$container = $this->createContainerFromFile('http_client_override_default_options');

0 commit comments

Comments
 (0)
0