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][aws-resolver] allow configure cache_prefix via factory. #370

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
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