Skip to content

Commit

Permalink
Merge pull request #367 from formapro-forks/set-web-path-as-default-r…
Browse files Browse the repository at this point in the history
…esolver

[1.0] set web_path resolver as default if not configured.
  • Loading branch information
makasim committed Mar 27, 2014
2 parents e2dbe6c + 951486a commit 33b388e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
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

0 comments on commit 33b388e

Please sign in to comment.