Skip to content

Commit

Permalink
Merge pull request #110 from FriendsOfSymfony/configuration-test-vari…
Browse files Browse the repository at this point in the history
…ants

add tests for splitting configuration options
  • Loading branch information
dbu committed Jul 20, 2014
2 parents 6684048 + 11de465 commit 540a455
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private function addMatch(NodeBuilder $rules)
->info('Additional response HTTP status codes that will match.')
->end()
->scalarNode('match_response')
->defaultValue(array())
->defaultNull()
->info('Expression to decide whether response should be matched. Replaces HTTP code check and additional_cacheable_status.')
->end()
->end()
Expand Down
4 changes: 2 additions & 2 deletions Tests/Resources/Fixtures/config/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'path' => '/abc',
'host' => 'fos',
'methods' => array('GET', 'POST'),
'ips' => '1.2.3.4, 1.1.1.1',
'ips' => array('1.2.3.4', '1.1.1.1'),
'attributes' => array('_controller' => 'fos.user_bundle.*'),
'additional_cacheable_status' => array(100, 500),
),
Expand All @@ -26,7 +26,7 @@
),
'last_modified' => '-1 hour',
'reverse_proxy_ttl' => 42,
'vary' => 'Cookie,Authorization',
'vary' => array('Cookie', 'Authorization'),
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion Tests/Resources/Fixtures/config/full.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</rule>
</cache-control>
<proxy-client>
<varnish base-url="/test">
<varnish base-url="/test" guzzle-client="acme.guzzle.varnish">
<server>22.22.22.22</server>
</varnish>
</proxy-client>
Expand Down
2 changes: 1 addition & 1 deletion Tests/Resources/Fixtures/config/nginx.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<config xmlns="http://example.org/schema/dic/fos_http_cache">
<proxy-client>
<nginx base-url="/test" purge-location="/purge">
<nginx base-url="/test" purge-location="/purge" guzzle-client="acme.guzzle.nginx">
<server>22.22.22.22</server>
</nginx>
</proxy-client>
Expand Down
25 changes: 25 additions & 0 deletions Tests/Resources/Fixtures/config/split.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

$container->loadFromExtension('fos_http_cache', array(
'cache_control' => array(
'rules' => array(
array(
'match' => array(
'methods' => 'GET,POST',
'ips' => '1.2.3.4, 1.1.1.1',
),
'headers' => array(
'vary' => 'Cookie,Authorization',
),
),
),
),
'proxy_client' => array(
'varnish' => array(
'servers' => '1.1.1.1:80,2.2.2.2:80',
),
'nginx' => array(
'servers' => '1.1.1.1:81,2.2.2.2:81',
),
),
));
24 changes: 24 additions & 0 deletions Tests/Resources/Fixtures/config/split.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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-control>
<rule>
<match>
<methods>GET,POST</methods>
<ips>1.2.3.4,1.1.1.1</ips>
</match>
<headers vary="Cookie,Authorization" />
</rule>
</cache-control>
<proxy-client>
<varnish>
<servers>1.1.1.1:80,2.2.2.2:80</servers>
</varnish>
<nginx>
<servers>1.1.1.1:81,2.2.2.2:81</servers>
</nginx>
</proxy-client>
</config>

</container>
15 changes: 15 additions & 0 deletions Tests/Resources/Fixtures/config/split.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fos_http_cache:

cache_control:
rules:
-
match:
methods: GET,POST
ips: 1.2.3.4,1.1.1.1
headers:
vary: Cookie,Authorization
proxy_client:
varnish:
servers: 1.1.1.1:80, 2.2.2.2:80
nginx:
servers: 1.1.1.1:81, 2.2.2.2:81
57 changes: 54 additions & 3 deletions Tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testSupportsAllConfigFormats()
'ips' => array('1.2.3.4', '1.1.1.1'),
'attributes' => array('_controller' => 'fos.user_bundle.*'),
'additional_cacheable_status' => array(100, 500),
'match_response' => array(),
'match_response' => '',
// TODO 'match_response' => '',
),
'headers' => array(
Expand Down Expand Up @@ -103,7 +103,7 @@ public function testSupportsAllConfigFormats()
'_foo' => 'bar',
),
'additional_cacheable_status' => array(501, 502),
'match_response' => array(),
'match_response' => '',
// TODO match_response
),
'tags' => array('a', 'b'),
Expand All @@ -124,7 +124,7 @@ public function testSupportsAllConfigFormats()
'_format' => 'json',
),
'additional_cacheable_status' => array(404, 403),
'match_response' => array(),
'match_response' => '',
// TODO match_response
),
'routes' => array(
Expand Down Expand Up @@ -202,6 +202,57 @@ public function testSupportsNginx()
}
}

public function testSplitOptions()
{
$expectedConfiguration = $this->getEmptyConfig();
$expectedConfiguration['cache_control'] = array(
'rules' => array(
array(
'match' => array(
'path' => null,
'host' => null,
'attributes' => array(),
'additional_cacheable_status' => array(),
'match_response' => null,
'methods' => array('GET', 'POST'),
'ips' => array('1.2.3.4', '1.1.1.1'),
),
'headers' => array(
'reverse_proxy_ttl' => null,
'vary' => array('Cookie', 'Authorization'),
),
),
),
);
$expectedConfiguration['proxy_client'] = array(
'varnish' => array(
'base_url' => null,
'guzzle_client' => null,
'servers' => array('1.1.1.1:80', '2.2.2.2:80'),
),
'nginx' => array(
'base_url' => null,
'guzzle_client' => null,
'purge_location' => '',
'servers' => array('1.1.1.1:81', '2.2.2.2:81'),
),
);
$expectedConfiguration['cache_manager']['enabled'] = 'auto';
$expectedConfiguration['tags']['enabled'] = 'auto';
$expectedConfiguration['invalidation']['enabled'] = 'auto';

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

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

public function testCacheManagerNoClient()
{
Expand Down

0 comments on commit 540a455

Please sign in to comment.