From 999e879c53c2217f736293f7c1167317ab50782d Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Sat, 1 Feb 2020 16:21:44 +0100 Subject: [PATCH] Fix HTTP client config handling --- .../DependencyInjection/Configuration.php | 6 ++--- .../Fixtures/php/http_client_xml_key.php | 22 +++++++++++++++++++ .../Fixtures/xml/http_client_xml_key.xml | 19 ++++++++++++++++ .../Fixtures/yml/http_client_xml_key.yml | 12 ++++++++++ .../FrameworkExtensionTest.php | 15 +++++++++++++ 5 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/http_client_xml_key.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/http_client_xml_key.xml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/http_client_xml_key.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 4263acc5dd19c..c78a8aa1b4e03 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -1402,7 +1402,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode) if (!\is_array($config)) { return []; } - if (!isset($config['host'])) { + if (!isset($config['host'], $config['value']) || count($config) > 2) { return $config; } @@ -1511,7 +1511,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode) if (!\is_array($config)) { return []; } - if (!isset($config['key'])) { + if (!isset($config['key'], $config['value']) || count($config) > 2) { return $config; } @@ -1541,7 +1541,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode) if (!\is_array($config)) { return []; } - if (!isset($config['host'])) { + if (!isset($config['host'], $config['value']) || count($config) > 2) { return $config; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/http_client_xml_key.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/http_client_xml_key.php new file mode 100644 index 0000000000000..64778c61561b6 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/http_client_xml_key.php @@ -0,0 +1,22 @@ +loadFromExtension('framework', [ + 'http_client' => [ + 'default_options' => [ + 'resolve' => [ + 'host' => '127.0.0.1', + ], + ], + 'scoped_clients' => [ + 'foo' => [ + 'base_uri' => 'http://example.com', + 'query' => [ + 'key' => 'foo', + ], + 'resolve' => [ + 'host' => '127.0.0.1', + ], + ], + ], + ], +]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/http_client_xml_key.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/http_client_xml_key.xml new file mode 100644 index 0000000000000..95ef0737f8a02 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/http_client_xml_key.xml @@ -0,0 +1,19 @@ + + + + + + + 127.0.0.1 + + + foo + 127.0.0.1 + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/http_client_xml_key.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/http_client_xml_key.yml new file mode 100644 index 0000000000000..dc87555a901ae --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/http_client_xml_key.yml @@ -0,0 +1,12 @@ +framework: + http_client: + default_options: + resolve: + host: 127.0.0.1 + scoped_clients: + foo: + base_uri: http://example.com + query: + key: foo + resolve: + host: 127.0.0.1 diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 2d494932dfd42..25409cd87fe4b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -1559,6 +1559,21 @@ public function testHttpClientOverrideDefaultOptions() $this->assertSame($expected, $container->getDefinition('foo')->getArgument(2)); } + public function testHttpClientWithQueryParameterKey() + { + $container = $this->createContainerFromFile('http_client_xml_key'); + + $expected = [ + 'key' => 'foo', + ]; + $this->assertSame($expected, $container->getDefinition('foo')->getArgument(2)['query']); + + $expected = [ + 'host' => '127.0.0.1', + ]; + $this->assertSame($expected, $container->getDefinition('foo')->getArgument(2)['resolve']); + } + public function testHttpClientFullDefaultOptions() { $container = $this->createContainerFromFile('http_client_full_default_options');