Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 95f4d5f

Browse files
committed
add configuration tests
1 parent b859805 commit 95f4d5f

24 files changed

Lines changed: 764 additions & 34 deletions

DependencyInjection/Configuration.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function getConfigTreeBuilder()
6969

7070
return $v;
7171
}
72-
throw new InvalidConfigurationException('You need to configure a proxy_client to use the cache_manager.');
72+
throw new InvalidConfigurationException('You need to configure a proxy_client to get the cache_manager needed for tag handling.');
7373
})
7474
->end()
7575
->validate()
@@ -84,7 +84,7 @@ public function getConfigTreeBuilder()
8484

8585
return $v;
8686
}
87-
throw new InvalidConfigurationException('You need to configure a proxy_client to use the cache_manager.');
87+
throw new InvalidConfigurationException('You need to configure a proxy_client to get the cache_manager needed for invalidation handling.');
8888
})
8989
->end()
9090
->validate()
@@ -115,6 +115,7 @@ private function addCacheControlSection(ArrayNodeDefinition $rootNode)
115115
$rules = $rootNode
116116
->children()
117117
->arrayNode('cache_control')
118+
->fixXmlConfig('rule')
118119
->children()
119120
->arrayNode('rules')
120121
->prototype('array')
@@ -133,8 +134,8 @@ private function addCacheControlSection(ArrayNodeDefinition $rootNode)
133134
->end()
134135
->scalarNode('last_modified')
135136
->validate()
136-
->ifString()
137-
->then(function ($v) {new \DateTime($v);})
137+
->ifTrue(function ($v) {if (is_string($v)) {new \DateTime($v);} return false;})
138+
->thenInvalid('') // this will never happen as new DateTime will throw an exception if $v is no date
138139
->end()
139140
->info('Set a default last modified timestamp if none is set yet. Value must be parseable by DateTime')
140141
->end()
@@ -164,6 +165,8 @@ private function addMatch(NodeBuilder $rules)
164165
->cannotBeOverwritten()
165166
->isRequired()
166167
->fixXmlConfig('method')
168+
->fixXmlConfig('ip')
169+
->fixXmlConfig('attribute')
167170
->validate()
168171
->ifTrue(function ($v) {return !empty($v['additional_cacheable_status']) && !empty($v['match_response']);})
169172
->thenInvalid('You may not set both additional_cacheable_status and match_response.')
@@ -297,18 +300,18 @@ private function addTagSection(ArrayNodeDefinition $rootNode)
297300
$rules = $rootNode
298301
->children()
299302
->arrayNode('tags')
300-
->fixXmlConfig('rule')
301303
->addDefaultsIfNotSet()
304+
->fixXmlConfig('rule')
302305
->children()
303306
->enumNode('enabled')
304307
->values(array(true, false, 'auto'))
305308
->defaultValue('auto')
306309
->info('Allows to disable the listener for tag annotations when your project does not use the annotations. Enabled by default if you have expression language and the cache manager.')
307310
->end()
308311
->arrayNode('rules')
309-
->fixXmlConfig('tag')
310-
->fixXmlConfig('tag_expression')
311312
->prototype('array')
313+
->fixXmlConfig('tag')
314+
->fixXmlConfig('tag_expression')
312315
->children();
313316

314317
$this->addMatch($rules);
@@ -454,6 +457,7 @@ private function addDebugSection(ArrayNodeDefinition $rootNode)
454457
->children()
455458
->arrayNode('debug')
456459
->addDefaultsIfNotSet()
460+
->canBeEnabled()
457461
->children()
458462
->booleanNode('enabled')
459463
->defaultValue($this->debug)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
$container->loadFromExtension('fos_http_cache', array(
4+
'cache_manager' => array(
5+
'enabled' => true,
6+
),
7+
));
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fos_http_cache:
2+
3+
cache_manager:
4+
enabled: true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
$container->loadFromExtension('fos_http_cache', array());
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fos_http_cache:
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
$container->loadFromExtension('fos_http_cache', array(
4+
'cache_control' => array(
5+
'rules' => array(
6+
array(
7+
'match' => array(
8+
'path' => '/abc',
9+
'host' => 'fos',
10+
'methods' => array('GET', 'POST'),
11+
'ips' => '1.2.3.4, 1.1.1.1',
12+
'attributes' => array('_controller' => 'fos.user_bundle.*'),
13+
'additional_cacheable_status' => array(100, 500),
14+
),
15+
'headers' => array(
16+
'cache_control' => array(
17+
'public' => true,
18+
),
19+
'last_modified' => '-1 hour',
20+
'reverse_proxy_ttl' => 42,
21+
'vary' => 'Cookie',
22+
),
23+
),
24+
),
25+
),
26+
'proxy_client' => array(
27+
'varnish' => array(
28+
'servers' => array('22.22.22.22'),
29+
'base_url' => '/test',
30+
),
31+
),
32+
33+
'cache_manager' => array(
34+
'enabled' => true,
35+
),
36+
'tags' => array(
37+
'rules' => array(
38+
array(
39+
'match' => array(
40+
'path' => '/def',
41+
'host' => 'friends',
42+
'methods' => array('PUT', 'DELETE'),
43+
'ips' => '99.99.99.99',
44+
'attributes' => array(
45+
'_foo' => 'bar',
46+
),
47+
'additional_cacheable_status' => array(501, 502),
48+
),
49+
'tags' => array('a', 'b'),
50+
'tag_expressions' => array('"a"', '"b"'),
51+
),
52+
),
53+
),
54+
'invalidation' => array(
55+
'enabled' => 'auto',
56+
'rules' => array(
57+
array(
58+
'match' => array(
59+
'path' => '/hij',
60+
'host' => 'symfony',
61+
'methods' => array('PATCH'),
62+
'ips' => array('42.42.42.42'),
63+
'attributes' => array(
64+
'_format' => 'json',
65+
),
66+
'additional_cacheable_status' => array(404, 403),
67+
),
68+
'routes' => array(
69+
'invalidate_route1' => array(
70+
'ignore_extra_params' => false,
71+
),
72+
),
73+
),
74+
),
75+
),
76+
'user_context' => array(
77+
'enabled' => true,
78+
'match' => array(
79+
'matcher_service' => 'fos_http_cache.user_context.request_matcher',
80+
'accept' => 'application/vnd.fos.user-context-hash',
81+
'method' => 'GET',
82+
),
83+
'hash_cache_ttl' => 300,
84+
'user_identifier_headers' => array('Cookie', 'Authorization'),
85+
'user_hash_header' => 'FOS-User-Context-Hash',
86+
'role_provider' => true,
87+
),
88+
'flash_message_listener' => array(
89+
'enabled' => true,
90+
'name' => 'flashtest',
91+
'path' => '/x',
92+
'host' => 'y',
93+
'secure' => true,
94+
'httpOnly' => false,
95+
),
96+
'debug' => array(
97+
'header' => 'FOS-Cache-Debug',
98+
),
99+
100+
));
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
fos_http_cache:
2+
3+
cache_control:
4+
rules:
5+
-
6+
match:
7+
path: /abc
8+
host: fos
9+
methods:
10+
- GET
11+
- POST
12+
ips:
13+
- 1.2.3.4
14+
- 1.1.1.1
15+
attributes:
16+
_controller: fos.user_bundle.*
17+
additional_cacheable_status:
18+
- 100
19+
- 500
20+
headers:
21+
cache_control:
22+
public: true
23+
last_modified: -1 hour
24+
reverse_proxy_ttl: 42
25+
vary: Cookie
26+
proxy_client:
27+
varnish:
28+
servers: 22.22.22.22
29+
base_url: /test
30+
31+
cache_manager:
32+
enabled: true
33+
34+
tags:
35+
rules:
36+
-
37+
match:
38+
path: /def
39+
host: friends
40+
methods:
41+
- PUT
42+
- DELETE
43+
ips: 99.99.99.99
44+
attributes:
45+
_foo: bar
46+
additional_cacheable_status:
47+
- 501
48+
- 502
49+
tags:
50+
- a
51+
- b
52+
tag_expressions:
53+
- '"a"'
54+
- '"b"'
55+
56+
invalidation:
57+
rules:
58+
-
59+
match:
60+
path: /hij
61+
host: symfony
62+
methods: PATCH
63+
ips: 42.42.42.42
64+
attributes:
65+
_format: json
66+
additional_cacheable_status:
67+
- 404
68+
- 403
69+
routes:
70+
invalidate_route1:
71+
ignore_extra_params: false
72+
73+
user_context:
74+
match:
75+
method: GET
76+
hash_cache_ttl: 300
77+
role_provider: true
78+
user_identifier_headers:
79+
- Cookie
80+
- Authorization
81+
user_hash_header: FOS-User-Context-Hash
82+
83+
flash_message_listener:
84+
name: flashtest
85+
path: /x
86+
host: y
87+
secure: true
88+
httpOnly: false
89+
90+
debug:
91+
header: FOS-Cache-Debug
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
$container->loadFromExtension('fos_http_cache', array(
4+
'cache_control' => array(
5+
'rules' => array(
6+
array(
7+
'match' => array(
8+
'path' => '/abc',
9+
),
10+
'headers' => array(
11+
'last_modified' => 'this is no date',
12+
),
13+
),
14+
),
15+
),
16+
));
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fos_http_cache:
2+
3+
cache_control:
4+
rules:
5+
-
6+
match:
7+
path: /abc
8+
headers:
9+
last_modified: this is no date
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
$container->loadFromExtension('fos_http_cache', array(
4+
'cache_manager' => array(
5+
'enabled' => false,
6+
),
7+
'invalidation' => array(
8+
'enabled' => true,
9+
),
10+
));

0 commit comments

Comments
 (0)