1 | <?php |
||
23 | class SymfonyCacheTest extends \PHPUnit_Framework_TestCase |
||
24 | { |
||
25 | /** |
||
26 | * @var SymfonyCache |
||
27 | */ |
||
28 | protected $cache; |
||
29 | |||
30 | /** |
||
31 | * @var RouterInterface |
||
32 | */ |
||
33 | protected $router; |
||
34 | |||
35 | /** |
||
36 | * @var Filesystem |
||
37 | */ |
||
38 | protected $filesystem; |
||
39 | |||
40 | /** |
||
41 | * Sets up cache adapter. |
||
42 | */ |
||
43 | protected function setUp() |
||
50 | |||
51 | /** |
||
52 | * Tests cache initialization. |
||
53 | */ |
||
54 | public function testInitCache() |
||
68 | |||
69 | /** |
||
70 | * Tests cacheAction() method. |
||
71 | */ |
||
72 | public function testCacheAction() |
||
90 | |||
91 | /** |
||
92 | * Tests cacheAction() method with an invalid token. |
||
93 | */ |
||
94 | public function testCacheActionWithInvalidToken() |
||
102 | |||
103 | /** |
||
104 | * Tests cacheAction() method with an invalid cache type. |
||
105 | */ |
||
106 | public function testCacheActionWithInvalidType() |
||
114 | |||
115 | /** |
||
116 | * Asserts the flush method throws an exception if the IP version of the server cannot be detected. |
||
117 | */ |
||
118 | public function testFlushThrowsExceptionWithWrongIP() |
||
119 | { |
||
120 | $cache = new SymfonyCache( |
||
121 | $this->router, |
||
122 | $this->filesystem, |
||
123 | '/cache/dir', |
||
124 | 'token', |
||
125 | false, |
||
126 | array('all', 'translations'), |
||
127 | array( |
||
128 | array('ip' => 'wrong ip'), |
||
129 | ) |
||
130 | ); |
||
131 | |||
132 | $this->setExpectedException('\InvalidArgumentException', '"wrong ip" is not a valid ip address'); |
||
133 | |||
134 | $cache->flush(); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Tests the flush method with IPv4. |
||
139 | */ |
||
140 | public function testFlushWithIPv4() |
||
141 | { |
||
142 | $mockBuilderClass = $this->getMockBuilderClass(); |
||
143 | |||
144 | $cache = new SymfonyCache( |
||
145 | $this->router, |
||
146 | $this->filesystem, |
||
147 | '/cache/dir', |
||
148 | 'token', |
||
149 | false, |
||
150 | array('all', 'translations'), |
||
151 | array( |
||
152 | array('ip' => '213.186.35.9', 'domain' => 'www.example.com', 'basic' => false, 'port' => 80), |
||
153 | ) |
||
154 | ); |
||
155 | |||
156 | $that = $this; |
||
157 | $mocks = array(); |
||
158 | |||
159 | $builder = new $mockBuilderClass(); |
||
160 | $mock = $builder->setNamespace('Sonata\CacheBundle\Adapter') |
||
161 | ->setName('socket_create') |
||
162 | ->setFunction(function () use ($that) { |
||
163 | $that->assertSame(array(AF_INET, SOCK_STREAM, SOL_TCP), func_get_args()); |
||
164 | }) |
||
165 | ->build(); |
||
166 | $mock->enable(); |
||
167 | |||
168 | $mocks[] = $mock; |
||
169 | |||
170 | foreach (array('socket_set_option', 'socket_connect', 'socket_write', 'socket_read') as $function) { |
||
171 | $builder = new $mockBuilderClass(); |
||
172 | $mock = $builder->setNamespace('Sonata\CacheBundle\Adapter') |
||
173 | ->setName($function) |
||
174 | ->setFunction(function () { |
||
175 | }) |
||
176 | ->build(); |
||
177 | $mock->enable(); |
||
178 | |||
179 | $mocks[] = $mock; |
||
180 | } |
||
181 | |||
182 | $cache->flush(); |
||
183 | |||
184 | foreach ($mocks as $mock) { |
||
185 | $mock->disable(); |
||
186 | } |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * Tests the flush method with IPv6. |
||
191 | */ |
||
192 | public function testFlushWithIPv6() |
||
193 | { |
||
194 | $mockBuilderClass = $this->getMockBuilderClass(); |
||
195 | |||
196 | $cache = new SymfonyCache( |
||
197 | $this->router, |
||
198 | $this->filesystem, |
||
199 | '/cache/dir', |
||
200 | 'token', |
||
201 | false, |
||
202 | array('all', 'translations'), |
||
203 | array( |
||
204 | array('ip' => '2001:41d0:1:209:FF:FF:FF:FF', 'domain' => 'www.example.com', 'basic' => false, 'port' => 80), |
||
205 | ) |
||
206 | ); |
||
207 | |||
208 | $that = $this; |
||
209 | $mocks = array(); |
||
210 | |||
211 | $builder = new $mockBuilderClass(); |
||
212 | $mock = $builder->setNamespace('Sonata\CacheBundle\Adapter') |
||
213 | ->setName('socket_create') |
||
214 | ->setFunction(function () use ($that) { |
||
215 | $that->assertSame(array(AF_INET6, SOCK_STREAM, SOL_TCP), func_get_args()); |
||
216 | }) |
||
217 | ->build(); |
||
218 | $mock->enable(); |
||
219 | |||
220 | $mocks[] = $mock; |
||
221 | |||
222 | foreach (array('socket_set_option', 'socket_connect', 'socket_write', 'socket_read') as $function) { |
||
223 | $builder = new $mockBuilderClass(); |
||
224 | $mock = $builder->setNamespace('Sonata\CacheBundle\Adapter') |
||
225 | ->setName($function) |
||
226 | ->setFunction(function () { |
||
227 | }) |
||
228 | ->build(); |
||
229 | $mock->enable(); |
||
230 | |||
231 | $mocks[] = $mock; |
||
232 | } |
||
233 | |||
234 | $cache->flush(); |
||
235 | |||
236 | foreach ($mocks as $mock) { |
||
237 | $mock->disable(); |
||
238 | } |
||
239 | } |
||
240 | |||
241 | /** |
||
242 | * Gets the mock builder class according to the lib version (ie the PHP version). |
||
243 | * NEXT_MAJOR: while dropping old versions of php, restrict the library to version ^1.0 and simplify this. |
||
244 | * |
||
245 | * @return string |
||
246 | */ |
||
247 | private function getMockBuilderClass() |
||
257 | } |
||
258 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.