diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index a23d193a3..8de9b12fa 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -41,8 +41,20 @@ public function getConfigTreeBuilder() $resolversPrototypeNode = $rootNode ->children() ->arrayNode('resolvers') - ->useAttributeAsKey('name') - ->prototype('array') + ->beforeNormalization() + ->ifTrue(function ($v) { return !is_array($v) || (is_array($v) && !array_key_exists('default', $v)); }) + ->then(function ($v) { + if (false == is_array($v)) { + $v = array(); + } + + $v['default'] = array('web_path' => null); + + return $v; + }) + ->end() + ->useAttributeAsKey('name') + ->prototype('array') ; $this->addResolversSections($resolversPrototypeNode); diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index 26baf6ab0..7f9febed2 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -4,6 +4,7 @@ use Liip\ImagineBundle\DependencyInjection\Configuration; use Liip\ImagineBundle\DependencyInjection\Factory\Loader\LoaderFactoryInterface; use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\ResolverFactoryInterface; +use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\WebPathResolverFactory; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Definition\Processor; @@ -75,7 +76,7 @@ public function testAllowToUseLoaderFactorySeveralTimes() public function testInjectResolverFactoryConfig() { $config = $this->processConfiguration( - new Configuration(array(new BarResolverFactory), array()), + new Configuration(array(new BarResolverFactory, new WebPathResolverFactory), array()), array(array( 'resolvers' => array( 'aResolver' => array( @@ -98,7 +99,7 @@ public function testInjectResolverFactoryConfig() public function testAllowToUseResolverFactorySeveralTimes() { $config = $this->processConfiguration( - new Configuration(array(new BarResolverFactory), array()), + new Configuration(array(new BarResolverFactory, new WebPathResolverFactory), array()), array(array( 'resolvers' => array( 'aResolver' => array( @@ -121,6 +122,42 @@ public function testAllowToUseResolverFactorySeveralTimes() $this->assertArrayHasKey('anotherResolver', $config['resolvers']); } + public function testSetWebPathAsDefaultResolverIfNotDefined() + { + $config = $this->processConfiguration( + new Configuration(array(new WebPathResolverFactory), array()), + array(array( + 'resolvers' => array( + ) + )) + ); + + $this->assertArrayHasKey('resolvers', $config); + $this->assertArrayHasKey('default', $config['resolvers']); + $this->assertArrayHasKey('web_path', $config['resolvers']['default']); + } + + public function testShouldNotOverwriteDefaultResolverIfDefined() + { + $config = $this->processConfiguration( + new Configuration(array(new BarResolverFactory, new WebPathResolverFactory), array()), + array(array( + 'resolvers' => array( + 'default' => array( + 'bar' => array( + 'bar_option' => 'theValue' + ) + ), + ) + + )) + ); + + $this->assertArrayHasKey('resolvers', $config); + $this->assertArrayHasKey('default', $config['resolvers']); + $this->assertArrayHasKey('bar', $config['resolvers']['default']); + } + /** * @param ConfigurationInterface $configuration * @param array $configs