Skip to content

Commit

Permalink
Merge pull request #248 from gregurco/issue_247
Browse files Browse the repository at this point in the history
Fix issue with merging of bundle configuration
  • Loading branch information
gregurco committed Dec 24, 2018
2 parents 2b23030 + 4637c35 commit b7e1cf2
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"require-dev": {
"symfony/phpunit-bridge": "~2.7|~3.0|~4.0",
"symfony/twig-bundle": "~2.7|~3.0|~4.0",
"symfony/var-dumper": "~2.7|~3.0|~4.0"
"symfony/var-dumper": "~2.7|~3.0|~4.0",
"symfony/yaml": "~2.7|~3.0|~4.0"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 6 additions & 6 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private function createClientsNode() : ArrayNodeDefinition
$node = $builder->root('clients');
}

/** @var \Symfony\Component\Config\Definition\Builder\NodeBuilder $nodeChildren */
$nodeChildren = $node->useAttributeAsKey('name')
->prototype('array')
->children();
Expand Down Expand Up @@ -119,9 +120,9 @@ private function createClientsNode() : ArrayNodeDefinition
->end()
->children()
->arrayNode('headers')
->useAttributeAsKey('name')
->normalizeKeys(false)
->prototype('scalar')
->end()
->prototype('scalar')->end()
->end()
->variableNode('allow_redirects')
->validate()
Expand Down Expand Up @@ -206,12 +207,11 @@ private function createClientsNode() : ArrayNodeDefinition
->end()
->floatNode('delay')->end()
->arrayNode('form_params')
->prototype('variable')
->end()
->useAttributeAsKey('name')
->prototype('variable')->end()
->end()
->arrayNode('multipart')
->prototype('variable')
->end()
->prototype('variable')->end()
->end()
->scalarNode('sink')
->validate()
Expand Down
24 changes: 24 additions & 0 deletions tests/DependencyInjection/EightPointsGuzzleExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use Psr\Log\LoggerInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use PHPUnit\Framework\TestCase;
use GuzzleHttp\Psr7\Uri;
Expand Down Expand Up @@ -343,6 +345,28 @@ public function testCompilation()
$this->assertInstanceOf(Client::class, $container->get('eight_points_guzzle.client.test_api_with_custom_handler'));
}

public function testMergingOfConfigurations()
{
$container = $this->createContainer();
$container->registerExtension(new EightPointsGuzzleExtension());
$container->setResourceTracking(false);
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Fixtures/config'));
$loader->load('test_api_1.yaml');
$loader->load('test_api_2.yaml');
$container->compile();

$this->assertTrue($container->hasDefinition('eight_points_guzzle.client.test_api'));
$this->assertEquals(
['foobar' => 'test', 'foobaz' => 'test'],
$container->getDefinition('eight_points_guzzle.client.test_api')->getArgument(0)['headers']
);

$this->assertEquals(
['param1' => 1, 'param2' => 2],
$container->getDefinition('eight_points_guzzle.client.test_api')->getArgument(0)['form_params']
);
}

/**
* @return \Symfony\Component\DependencyInjection\ContainerBuilder
*/
Expand Down
8 changes: 8 additions & 0 deletions tests/Fixtures/config/test_api_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
eight_points_guzzle:
clients:
test_api:
options:
headers:
foobar: 'test'
form_params:
param1: 1
8 changes: 8 additions & 0 deletions tests/Fixtures/config/test_api_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
eight_points_guzzle:
clients:
test_api:
options:
headers:
foobaz: 'test'
form_params:
param2: 2

0 comments on commit b7e1cf2

Please sign in to comment.