Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.0] set web_path resolver as default if not configured. #367

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
41 changes: 39 additions & 2 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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
Expand Down