Skip to content

Commit

Permalink
Merge pull request #370 from formapro-forks/aws-s3-resolver-configure…
Browse files Browse the repository at this point in the history
…-cache-prefix

[1.0][aws-resolver] allow configure cache_prefix via factory.
  • Loading branch information
makasim committed Mar 28, 2014
2 parents 33b388e + 66a8e01 commit cd4c0e2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
5 changes: 5 additions & 0 deletions DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public function create(ContainerBuilder $container, $resolverName, array $config
$resolverId = 'liip_imagine.cache.resolver.'.$resolverName;
$container->setDefinition($resolverId, $resolverDefinition);

if (isset($config['cache_prefix'])) {
$resolverDefinition->addMethodCall('setCachePrefix', array($config['cache_prefix']));
}

if ($config['cache']) {
$internalResolverId = 'liip_imagine.cache.resolver.'.$resolverName.'.internal';

Expand Down Expand Up @@ -68,6 +72,7 @@ public function addConfiguration(ArrayNodeDefinition $builder)
->scalarNode('bucket')->isRequired()->cannotBeEmpty()->end()
->scalarNode('cache')->defaultValue(false)->end()
->scalarNode('acl')->defaultValue('public-read')->cannotBeEmpty()->end()
->scalarNode('cache_prefix')->defaultValue(null)->end()
->arrayNode('client_config')
->isRequired()
->useAttributeAsKey('key')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,31 @@ public function testWrapResolverWithCacheOnCreate()
$this->assertEquals('liip_imagine.cache.resolver.theresolvername.internal', $resolverDefinition->getArgument(1));
}

public function testSetCachePrefixIfDefined()
{
$container = new ContainerBuilder;

$resolver = new AwsS3ResolverFactory;

$resolver->create($container, 'theResolverName', array(
'client_config' => array(),
'bucket' => 'aBucket',
'acl' => 'aAcl',
'url_options' => array(),
'cache_prefix' => 'theCachePrefix',
'cache' => null,
));

$this->assertTrue($container->hasDefinition('liip_imagine.cache.resolver.theresolvername'));
$resolverDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername');

$methodCalls = $resolverDefinition->getMethodCalls();

$this->assertCount(1, $methodCalls);
$this->assertEquals('setCachePrefix', $methodCalls[0][0]);
$this->assertEquals(array('theCachePrefix'), $methodCalls[0][1]);
}

/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage The child node "bucket" at path "aws_s3" must be configured.
Expand All @@ -128,7 +153,7 @@ public function testThrowBucketNotSetOnAddConfiguration()
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage The child node "client_config" at path "aws_s3" must be configured.
*/
public function testThrowClientConfinNotSetOnAddConfiguration()
public function testThrowClientConfigNotSetOnAddConfiguration()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('aws_s3', 'array');
Expand All @@ -147,7 +172,7 @@ public function testThrowClientConfinNotSetOnAddConfiguration()
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage Invalid type for path "aws_s3.client_config". Expected array, but got string
*/
public function testThrowClientConfinNotArrayOnAddConfiguration()
public function testThrowClientConfigNotArrayOnAddConfiguration()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('aws_s3', 'array');
Expand Down Expand Up @@ -175,6 +200,7 @@ public function testProcessCorrectlyOptionsOnAddConfiguration()
);
$expectedBucket = 'theBucket';
$expectedAcl = 'theAcl';
$expectedCachePrefix = 'theCachePrefix';

$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('aws_s3', 'array');
Expand All @@ -187,7 +213,8 @@ public function testProcessCorrectlyOptionsOnAddConfiguration()
'bucket' => $expectedBucket,
'acl' => $expectedAcl,
'client_config' => $expectedClientConfig,
'url_options' => $expectedUrlOptions
'url_options' => $expectedUrlOptions,
'cache_prefix' => $expectedCachePrefix,
)
));

Expand All @@ -202,6 +229,9 @@ public function testProcessCorrectlyOptionsOnAddConfiguration()

$this->assertArrayHasKey('url_options', $config);
$this->assertEquals($expectedUrlOptions, $config['url_options']);

$this->assertArrayHasKey('cache_prefix', $config);
$this->assertEquals($expectedCachePrefix, $config['cache_prefix']);
}

public function testAddDefaultOptionsIfNotSetOnAddConfiguration()
Expand All @@ -226,6 +256,9 @@ public function testAddDefaultOptionsIfNotSetOnAddConfiguration()

$this->assertArrayHasKey('url_options', $config);
$this->assertEquals(array(), $config['url_options']);

$this->assertArrayHasKey('cache_prefix', $config);
$this->assertNull($config['cache_prefix']);
}

/**
Expand Down

0 comments on commit cd4c0e2

Please sign in to comment.