Skip to content

Commit 540a455

Browse files
committed
Merge pull request #110 from FriendsOfSymfony/configuration-test-variants
add tests for splitting configuration options
2 parents 6684048 + 11de465 commit 540a455

File tree

8 files changed

+123
-8
lines changed

8 files changed

+123
-8
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private function addMatch(NodeBuilder $rules)
212212
->info('Additional response HTTP status codes that will match.')
213213
->end()
214214
->scalarNode('match_response')
215-
->defaultValue(array())
215+
->defaultNull()
216216
->info('Expression to decide whether response should be matched. Replaces HTTP code check and additional_cacheable_status.')
217217
->end()
218218
->end()

Tests/Resources/Fixtures/config/full.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'path' => '/abc',
99
'host' => 'fos',
1010
'methods' => array('GET', 'POST'),
11-
'ips' => '1.2.3.4, 1.1.1.1',
11+
'ips' => array('1.2.3.4', '1.1.1.1'),
1212
'attributes' => array('_controller' => 'fos.user_bundle.*'),
1313
'additional_cacheable_status' => array(100, 500),
1414
),
@@ -26,7 +26,7 @@
2626
),
2727
'last_modified' => '-1 hour',
2828
'reverse_proxy_ttl' => 42,
29-
'vary' => 'Cookie,Authorization',
29+
'vary' => array('Cookie', 'Authorization'),
3030
),
3131
),
3232
),

Tests/Resources/Fixtures/config/full.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</rule>
3535
</cache-control>
3636
<proxy-client>
37-
<varnish base-url="/test">
37+
<varnish base-url="/test" guzzle-client="acme.guzzle.varnish">
3838
<server>22.22.22.22</server>
3939
</varnish>
4040
</proxy-client>

Tests/Resources/Fixtures/config/nginx.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<config xmlns="http://example.org/schema/dic/fos_http_cache">
55
<proxy-client>
6-
<nginx base-url="/test" purge-location="/purge">
6+
<nginx base-url="/test" purge-location="/purge" guzzle-client="acme.guzzle.nginx">
77
<server>22.22.22.22</server>
88
</nginx>
99
</proxy-client>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
$container->loadFromExtension('fos_http_cache', array(
4+
'cache_control' => array(
5+
'rules' => array(
6+
array(
7+
'match' => array(
8+
'methods' => 'GET,POST',
9+
'ips' => '1.2.3.4, 1.1.1.1',
10+
),
11+
'headers' => array(
12+
'vary' => 'Cookie,Authorization',
13+
),
14+
),
15+
),
16+
),
17+
'proxy_client' => array(
18+
'varnish' => array(
19+
'servers' => '1.1.1.1:80,2.2.2.2:80',
20+
),
21+
'nginx' => array(
22+
'servers' => '1.1.1.1:81,2.2.2.2:81',
23+
),
24+
),
25+
));
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services">
3+
4+
<config xmlns="http://example.org/schema/dic/fos_http_cache">
5+
<cache-control>
6+
<rule>
7+
<match>
8+
<methods>GET,POST</methods>
9+
<ips>1.2.3.4,1.1.1.1</ips>
10+
</match>
11+
<headers vary="Cookie,Authorization" />
12+
</rule>
13+
</cache-control>
14+
<proxy-client>
15+
<varnish>
16+
<servers>1.1.1.1:80,2.2.2.2:80</servers>
17+
</varnish>
18+
<nginx>
19+
<servers>1.1.1.1:81,2.2.2.2:81</servers>
20+
</nginx>
21+
</proxy-client>
22+
</config>
23+
24+
</container>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
fos_http_cache:
2+
3+
cache_control:
4+
rules:
5+
-
6+
match:
7+
methods: GET,POST
8+
ips: 1.2.3.4,1.1.1.1
9+
headers:
10+
vary: Cookie,Authorization
11+
proxy_client:
12+
varnish:
13+
servers: 1.1.1.1:80, 2.2.2.2:80
14+
nginx:
15+
servers: 1.1.1.1:81, 2.2.2.2:81

Tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testSupportsAllConfigFormats()
5858
'ips' => array('1.2.3.4', '1.1.1.1'),
5959
'attributes' => array('_controller' => 'fos.user_bundle.*'),
6060
'additional_cacheable_status' => array(100, 500),
61-
'match_response' => array(),
61+
'match_response' => '',
6262
// TODO 'match_response' => '',
6363
),
6464
'headers' => array(
@@ -103,7 +103,7 @@ public function testSupportsAllConfigFormats()
103103
'_foo' => 'bar',
104104
),
105105
'additional_cacheable_status' => array(501, 502),
106-
'match_response' => array(),
106+
'match_response' => '',
107107
// TODO match_response
108108
),
109109
'tags' => array('a', 'b'),
@@ -124,7 +124,7 @@ public function testSupportsAllConfigFormats()
124124
'_format' => 'json',
125125
),
126126
'additional_cacheable_status' => array(404, 403),
127-
'match_response' => array(),
127+
'match_response' => '',
128128
// TODO match_response
129129
),
130130
'routes' => array(
@@ -202,6 +202,57 @@ public function testSupportsNginx()
202202
}
203203
}
204204

205+
public function testSplitOptions()
206+
{
207+
$expectedConfiguration = $this->getEmptyConfig();
208+
$expectedConfiguration['cache_control'] = array(
209+
'rules' => array(
210+
array(
211+
'match' => array(
212+
'path' => null,
213+
'host' => null,
214+
'attributes' => array(),
215+
'additional_cacheable_status' => array(),
216+
'match_response' => null,
217+
'methods' => array('GET', 'POST'),
218+
'ips' => array('1.2.3.4', '1.1.1.1'),
219+
),
220+
'headers' => array(
221+
'reverse_proxy_ttl' => null,
222+
'vary' => array('Cookie', 'Authorization'),
223+
),
224+
),
225+
),
226+
);
227+
$expectedConfiguration['proxy_client'] = array(
228+
'varnish' => array(
229+
'base_url' => null,
230+
'guzzle_client' => null,
231+
'servers' => array('1.1.1.1:80', '2.2.2.2:80'),
232+
),
233+
'nginx' => array(
234+
'base_url' => null,
235+
'guzzle_client' => null,
236+
'purge_location' => '',
237+
'servers' => array('1.1.1.1:81', '2.2.2.2:81'),
238+
),
239+
);
240+
$expectedConfiguration['cache_manager']['enabled'] = 'auto';
241+
$expectedConfiguration['tags']['enabled'] = 'auto';
242+
$expectedConfiguration['invalidation']['enabled'] = 'auto';
243+
244+
$formats = array_map(function ($path) {
245+
return __DIR__.'/../../Resources/Fixtures/'.$path;
246+
}, array(
247+
'config/split.yml',
248+
'config/split.xml',
249+
'config/split.php',
250+
));
251+
252+
foreach ($formats as $format) {
253+
$this->assertProcessedConfigurationEquals($expectedConfiguration, array($format));
254+
}
255+
}
205256

206257
public function testCacheManagerNoClient()
207258
{

0 commit comments

Comments
 (0)