From f467c327de205b9149eb3423dbf61b5871e86611 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Mon, 21 Nov 2016 16:59:42 +0100 Subject: [PATCH] Allow overwriting rules in configuration --- DependencyInjection/Configuration.php | 2 +- .../DependencyInjection/ConfigurationTest.php | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index fa81fd4a2..b038c833b 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -339,7 +339,7 @@ private function addFormatListenerSection(ArrayNodeDefinition $rootNode) ->children() ->scalarNode('service')->defaultNull()->end() ->arrayNode('rules') - ->cannotBeOverwritten() + ->performNoDeepMerging() ->prototype('array') ->fixXmlConfig('priority', 'priorities') ->fixXmlConfig('attribute', 'attributes') diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index e54f075b8..073b3a8d3 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -150,6 +150,54 @@ public function testLoadBadCodesClassThrowsException() ); } + public function testOverwriteFormatListenerRulesDoesNotMerge() + { + $configuration = $this->processor->processConfiguration( + $this->configuration, + [ + [ + 'format_listener' => [ + 'rules' => [ + [ + 'path' => '^/admin', + 'priorities' => ['html'], + ], + [ + 'path' => '^/', + 'priorities' => ['html', 'json'], + ], + ], + ], + ], + [ + 'format_listener' => [ + 'rules' => [ + [ + 'path' => '^/', + 'priorities' => ['json'], + ], + ], + ], + ], + ] + ); + + $expected = [ + [ + 'path' => '^/', + 'priorities' => ['json'], + 'host' => null, + 'methods' => null, + 'attributes' => [], + 'stop' => false, + 'prefer_extension' => true, + 'fallback_format' => 'html', + ], + ]; + + $this->assertEquals($expected, $configuration['format_listener']['rules']); + } + /** * incorrectExceptionCodeProvider. *