Skip to content

Commit

Permalink
Merge pull request #236 from FriendsOfSymfony/fix-custom-client-config
Browse files Browse the repository at this point in the history
fix how to configure a custom proxy client for the cache manager
  • Loading branch information
dbu committed Aug 20, 2015
2 parents ae7aca7 + c17eced commit aa20b2a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
10 changes: 6 additions & 4 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ public function getConfigTreeBuilder()

$rootNode
->validate()
->ifTrue(function ($v) {return $v['cache_manager']['enabled'] && !isset($v['proxy_client']);})
->ifTrue(function ($v) {
return $v['cache_manager']['enabled']
&& !isset($v['proxy_client'])
&& !isset($v['cache_manager']['custom_proxy_client'])
;
})
->then(function ($v) {
if (!empty($v['cache_manager']['proxy_client'])) {
return $v;
}
if ('auto' === $v['cache_manager']['enabled']) {
$v['cache_manager']['enabled'] = false;

Expand Down
8 changes: 8 additions & 0 deletions Tests/Resources/Fixtures/config/custom-client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

$container->loadFromExtension('fos_http_cache', array(
'cache_manager' => array(
'enabled' => true,
'custom_proxy_client' => 'acme.proxy_client',
),
));
7 changes: 7 additions & 0 deletions Tests/Resources/Fixtures/config/custom-client.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services">

<config xmlns="http://example.org/schema/dic/fos_http_cache">
<cache-manager enabled="true" custom-proxy-client="acme.proxy_client"/>
</config>
</container>
4 changes: 4 additions & 0 deletions Tests/Resources/Fixtures/config/custom-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fos_http_cache:
cache_manager:
enabled: true
custom_proxy_client: acme.proxy_client
24 changes: 24 additions & 0 deletions Tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,30 @@ public function testSupportsAllConfigFormats()
}
}

public function testCustomProxyClient()
{
$expectedConfiguration = $this->getEmptyConfig();
$expectedConfiguration['cache_manager'] = array(
'enabled' => true,
'custom_proxy_client' => 'acme.proxy_client',
'generate_url_type' => 'auto',
);
$expectedConfiguration['tags']['enabled'] = 'auto';
$expectedConfiguration['invalidation']['enabled'] = 'auto';

$formats = array_map(function ($path) {
return __DIR__.'/../../Resources/Fixtures/'.$path;
}, array(
'config/custom-client.yml',
'config/custom-client.xml',
'config/custom-client.php',
));

foreach ($formats as $format) {
$this->assertProcessedConfigurationEquals($expectedConfiguration, array($format));
}
}

public function testSupportsNginx()
{
$expectedConfiguration = $this->getEmptyConfig();
Expand Down

0 comments on commit aa20b2a

Please sign in to comment.