|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sonata Project package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sonata\CacheBundle\Tests\DependencyInjection\Configuration; |
|
13
|
|
|
|
|
14
|
|
|
use Sonata\CacheBundle\DependencyInjection\Configuration; |
|
15
|
|
|
use Symfony\Component\Config\Definition\Processor; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Tests the Configuration class. |
|
19
|
|
|
*/ |
|
20
|
|
|
class ConfigurationTest extends \PHPUnit_Framework_TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Asserts APC has default timeout values. |
|
24
|
|
|
*/ |
|
25
|
|
|
public function testApcDefaultTimeout() |
|
26
|
|
|
{ |
|
27
|
|
|
$configs = array(array( |
|
28
|
|
|
'caches' => array( |
|
29
|
|
|
'apc' => array( |
|
30
|
|
|
'token' => '', |
|
31
|
|
|
'prefix' => '', |
|
32
|
|
|
), |
|
33
|
|
|
), |
|
34
|
|
|
)); |
|
35
|
|
|
|
|
36
|
|
|
$config = $this->process($configs); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertArrayHasKey('timeout', $config['caches']['apc']); |
|
39
|
|
|
$this->assertSame( |
|
40
|
|
|
array( |
|
41
|
|
|
'RCV' => array(), |
|
42
|
|
|
'SND' => array(), |
|
43
|
|
|
), |
|
44
|
|
|
$config['caches']['apc']['timeout'] |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Asserts APC timeout has custom values. |
|
50
|
|
|
*/ |
|
51
|
|
|
public function testApcCustomTimeout() |
|
52
|
|
|
{ |
|
53
|
|
|
$expected = array( |
|
54
|
|
|
'RCV' => array('sec' => 10, 'usec' => 0), |
|
55
|
|
|
'SND' => array('sec' => 18, 'usec' => 12), |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
$configs = array(array( |
|
59
|
|
|
'caches' => array( |
|
60
|
|
|
'apc' => array( |
|
61
|
|
|
'token' => '', |
|
62
|
|
|
'prefix' => '', |
|
63
|
|
|
'timeout' => $expected, |
|
64
|
|
|
), |
|
65
|
|
|
), |
|
66
|
|
|
)); |
|
67
|
|
|
|
|
68
|
|
|
$config = $this->process($configs); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertArrayHasKey('timeout', $config['caches']['apc']); |
|
71
|
|
|
$this->assertSame($expected, $config['caches']['apc']['timeout']); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Asserts Symfony has default timeout values. |
|
76
|
|
|
*/ |
|
77
|
|
|
public function testSymfonyDefaultTimeout() |
|
78
|
|
|
{ |
|
79
|
|
|
$configs = array(array( |
|
80
|
|
|
'caches' => array( |
|
81
|
|
|
'symfony' => array( |
|
82
|
|
|
'token' => '', |
|
83
|
|
|
'types' => array('all'), |
|
84
|
|
|
), |
|
85
|
|
|
), |
|
86
|
|
|
)); |
|
87
|
|
|
|
|
88
|
|
|
$config = $this->process($configs); |
|
89
|
|
|
|
|
90
|
|
|
$this->assertArrayHasKey('timeout', $config['caches']['symfony']); |
|
91
|
|
|
$this->assertSame( |
|
92
|
|
|
array( |
|
93
|
|
|
'RCV' => array('sec' => 2, 'usec' => 0), |
|
94
|
|
|
'SND' => array('sec' => 2, 'usec' => 0), |
|
95
|
|
|
), |
|
96
|
|
|
$config['caches']['symfony']['timeout'] |
|
97
|
|
|
); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Asserts Symfony timeout has custom values. |
|
102
|
|
|
*/ |
|
103
|
|
|
public function testSymfonyCustomTimeout() |
|
104
|
|
|
{ |
|
105
|
|
|
$expected = array( |
|
106
|
|
|
'RCV' => array('sec' => 10, 'usec' => 0), |
|
107
|
|
|
'SND' => array('sec' => 18, 'usec' => 12), |
|
108
|
|
|
); |
|
109
|
|
|
|
|
110
|
|
|
$configs = array(array( |
|
111
|
|
|
'caches' => array( |
|
112
|
|
|
'symfony' => array( |
|
113
|
|
|
'token' => '', |
|
114
|
|
|
'types' => array('all'), |
|
115
|
|
|
'timeout' => $expected, |
|
116
|
|
|
), |
|
117
|
|
|
), |
|
118
|
|
|
)); |
|
119
|
|
|
|
|
120
|
|
|
$config = $this->process($configs); |
|
121
|
|
|
|
|
122
|
|
|
$this->assertArrayHasKey('timeout', $config['caches']['symfony']); |
|
123
|
|
|
$this->assertSame($expected, $config['caches']['symfony']['timeout']); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Processes an array of configurations and returns a compiled version. |
|
128
|
|
|
* |
|
129
|
|
|
* @param array $configs An array of raw configurations |
|
130
|
|
|
* |
|
131
|
|
|
* @return array A normalized array |
|
132
|
|
|
*/ |
|
133
|
|
|
protected function process(array $configs) |
|
134
|
|
|
{ |
|
135
|
|
|
$processor = new Processor(); |
|
136
|
|
|
|
|
137
|
|
|
return $processor->processConfiguration(new Configuration(), $configs); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|