From a07578dba3004f0923fc91b03563163c771e0708 Mon Sep 17 00:00:00 2001 From: Antonio Pauletich Date: Tue, 7 Apr 2020 13:57:54 +0200 Subject: [PATCH] [HttpClient] Fix scoped client without query option configuration --- .../DependencyInjection/Configuration.php | 2 +- .../http_client_scoped_without_query_option.php | 11 +++++++++++ .../http_client_scoped_without_query_option.xml | 16 ++++++++++++++++ .../http_client_scoped_without_query_option.yml | 5 +++++ .../FrameworkExtensionTest.php | 8 ++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/http_client_scoped_without_query_option.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/http_client_scoped_without_query_option.xml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/http_client_scoped_without_query_option.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 105695c963d9..13c63ff9988d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -1482,7 +1482,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode) ->thenInvalid('Either "scope" or "base_uri" should be defined.') ->end() ->validate() - ->ifTrue(function ($v) { return isset($v['query']) && !isset($v['base_uri']); }) + ->ifTrue(function ($v) { return !empty($v['query']) && !isset($v['base_uri']); }) ->thenInvalid('"query" applies to "base_uri" but no base URI is defined.') ->end() ->children() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/http_client_scoped_without_query_option.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/http_client_scoped_without_query_option.php new file mode 100644 index 000000000000..0d3dc88472f8 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/http_client_scoped_without_query_option.php @@ -0,0 +1,11 @@ +loadFromExtension('framework', [ + 'http_client' => [ + 'scoped_clients' => [ + 'foo' => [ + 'scope' => '.*', + ], + ], + ], +]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/http_client_scoped_without_query_option.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/http_client_scoped_without_query_option.xml new file mode 100644 index 000000000000..43043aeda2a0 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/http_client_scoped_without_query_option.xml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/http_client_scoped_without_query_option.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/http_client_scoped_without_query_option.yml new file mode 100644 index 000000000000..ecfc9d41fd4c --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/http_client_scoped_without_query_option.yml @@ -0,0 +1,5 @@ +framework: + http_client: + scoped_clients: + foo: + scope: '.*' diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index edcdb7aae487..9a8fc0776f0a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -1547,6 +1547,14 @@ public function testHttpClientDefaultOptions() $this->assertSame(ScopingHttpClient::class, $container->getDefinition('foo')->getClass()); } + public function testScopedHttpClientWithoutQueryOption() + { + $container = $this->createContainerFromFile('http_client_scoped_without_query_option'); + + $this->assertTrue($container->hasDefinition('foo'), 'should have the "foo" service.'); + $this->assertSame(ScopingHttpClient::class, $container->getDefinition('foo')->getClass()); + } + public function testHttpClientOverrideDefaultOptions() { $container = $this->createContainerFromFile('http_client_override_default_options');