1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FOSHttpCache package. |
5
|
|
|
* |
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
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 FOS\HttpCache\Test; |
13
|
|
|
|
14
|
|
|
use FOS\HttpCache\SymfonyCache\CacheEvent; |
15
|
|
|
use FOS\HttpCache\SymfonyCache\CacheInvalidation; |
16
|
|
|
use FOS\HttpCache\SymfonyCache\EventDispatchingHttpCache; |
17
|
|
|
use FOS\HttpCache\SymfonyCache\Events; |
18
|
|
|
use PHPUnit\Framework\TestCase; |
19
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
21
|
|
|
use Symfony\Component\HttpFoundation\Response; |
22
|
|
|
use Symfony\Component\HttpKernel\HttpCache\HttpCache; |
23
|
|
|
use Symfony\Component\HttpKernel\HttpCache\StoreInterface; |
24
|
|
|
use Symfony\Component\HttpKernel\HttpKernelInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* This test ensures that the EventDispatchingHttpCache trait is correctly used. |
28
|
|
|
*/ |
29
|
|
|
abstract class EventDispatchingHttpCacheTestCase extends TestCase |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Specify the CacheInvalidationInterface HttpCache class to test. |
33
|
|
|
* |
34
|
|
|
* @return string Fully qualified class name of the AppCache |
35
|
|
|
*/ |
36
|
|
|
abstract protected function getCacheClass(); |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Create a partial mock of the HttpCache to only test some methods. |
40
|
|
|
* |
41
|
|
|
* @param array $mockedMethods List of methods to mock |
42
|
|
|
* |
43
|
|
|
* @return CacheInvalidation|EventDispatchingHttpCache|\PHPUnit_Framework_MockObject_MockObject |
44
|
|
|
*/ |
45
|
9 |
|
protected function getHttpCachePartialMock(array $mockedMethods = null) |
46
|
|
|
{ |
47
|
|
|
$mock = $this |
48
|
9 |
|
->getMockBuilder($this->getCacheClass()) |
49
|
9 |
|
->setMethods($mockedMethods) |
50
|
9 |
|
->disableOriginalConstructor() |
51
|
9 |
|
->getMock() |
52
|
|
|
; |
53
|
|
|
|
54
|
9 |
|
$this->assertInstanceOf(CacheInvalidation::class, $mock); |
55
|
|
|
|
56
|
|
|
// Force setting options property since we can't use original constructor. |
57
|
|
|
$options = [ |
58
|
9 |
|
'debug' => false, |
59
|
|
|
'default_ttl' => 0, |
60
|
|
|
'private_headers' => ['Authorization', 'Cookie'], |
61
|
|
|
'allow_reload' => false, |
62
|
|
|
'allow_revalidate' => false, |
63
|
|
|
'stale_while_revalidate' => 2, |
64
|
|
|
'stale_if_error' => 60, |
65
|
|
|
]; |
66
|
|
|
|
67
|
9 |
|
$refHttpCache = new \ReflectionClass(HttpCache::class); |
68
|
|
|
// Workaround for Symfony 2 where $options property is not defined. |
69
|
9 |
|
if (!$refHttpCache->hasProperty('options')) { |
70
|
|
|
$mock->options = $options; |
71
|
|
|
} else { |
72
|
9 |
|
$refOptions = $refHttpCache->getProperty('options'); |
73
|
9 |
|
$refOptions->setAccessible(true); |
74
|
9 |
|
$refOptions->setValue($mock, $options); |
75
|
|
|
} |
76
|
|
|
|
77
|
9 |
|
return $mock; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Set the store property on a HttpCache to a StoreInterface expecting one write with request and response. |
82
|
|
|
* |
83
|
|
|
* @param CacheInvalidation $httpCache |
84
|
|
|
* @param Request $request |
85
|
|
|
* @param Response $response |
86
|
|
|
*/ |
87
|
2 |
|
protected function setStoreMock(CacheInvalidation $httpCache, Request $request, Response $response) |
88
|
|
|
{ |
89
|
2 |
|
$store = $this->createMock(StoreInterface::class); |
90
|
|
|
$store |
91
|
2 |
|
->expects($this->once()) |
92
|
2 |
|
->method('write') |
93
|
2 |
|
->with($request, $response) |
94
|
|
|
; |
95
|
2 |
|
$refHttpCache = new \ReflectionClass(HttpCache::class); |
96
|
2 |
|
$refStore = $refHttpCache->getProperty('store'); |
97
|
2 |
|
$refStore->setAccessible(true); |
98
|
2 |
|
$refStore->setValue($httpCache, $store); |
99
|
2 |
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Assert that preHandle and postHandle are called. |
103
|
|
|
*/ |
104
|
1 |
|
public function testHandleCalled() |
105
|
|
|
{ |
106
|
1 |
|
$catch = true; |
107
|
1 |
|
$request = Request::create('/foo', 'GET'); |
108
|
1 |
|
$response = new Response(); |
109
|
|
|
|
110
|
1 |
|
$httpCache = $this->getHttpCachePartialMock(['lookup']); |
111
|
1 |
|
$testListener = new TestListener($this, $httpCache, $request); |
|
|
|
|
112
|
1 |
|
$httpCache->addSubscriber($testListener); |
|
|
|
|
113
|
|
|
$httpCache |
|
|
|
|
114
|
1 |
|
->expects($this->any()) |
115
|
1 |
|
->method('lookup') |
116
|
1 |
|
->with($request) |
117
|
1 |
|
->will($this->returnValue($response)) |
118
|
|
|
; |
119
|
|
|
|
120
|
1 |
|
$this->assertSame($response, $httpCache->handle($request, HttpKernelInterface::MASTER_REQUEST, $catch)); |
|
|
|
|
121
|
1 |
|
$this->assertEquals(1, $testListener->preHandleCalls); |
122
|
1 |
|
$this->assertEquals(1, $testListener->postHandleCalls); |
123
|
1 |
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Assert that when preHandle returns a response, that response is used and the normal kernel flow stopped. |
127
|
|
|
* |
128
|
|
|
* @depends testHandleCalled |
129
|
|
|
*/ |
130
|
1 |
|
public function testPreHandleReturnEarly() |
131
|
|
|
{ |
132
|
1 |
|
$catch = true; |
133
|
1 |
|
$request = Request::create('/foo', 'GET'); |
134
|
1 |
|
$response = new Response(); |
135
|
|
|
|
136
|
1 |
|
$httpCache = $this->getHttpCachePartialMock(['lookup']); |
137
|
1 |
|
$testListener = new TestListener($this, $httpCache, $request); |
|
|
|
|
138
|
1 |
|
$testListener->preHandleResponse = $response; |
139
|
1 |
|
$httpCache->addSubscriber($testListener); |
|
|
|
|
140
|
|
|
$httpCache |
|
|
|
|
141
|
1 |
|
->expects($this->never()) |
142
|
1 |
|
->method('lookup') |
143
|
|
|
; |
144
|
|
|
|
145
|
1 |
|
$this->assertSame($response, $httpCache->handle($request, HttpKernelInterface::MASTER_REQUEST, $catch)); |
|
|
|
|
146
|
1 |
|
$this->assertEquals(1, $testListener->preHandleCalls); |
147
|
1 |
|
$this->assertEquals(1, $testListener->postHandleCalls); |
148
|
1 |
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Assert that postHandle can update the response. |
152
|
|
|
* |
153
|
|
|
* @depends testHandleCalled |
154
|
|
|
*/ |
155
|
1 |
|
public function testPostHandleReturn() |
156
|
|
|
{ |
157
|
1 |
|
$catch = true; |
158
|
1 |
|
$request = Request::create('/foo', 'GET'); |
159
|
1 |
|
$regularResponse = new Response(); |
160
|
1 |
|
$postResponse = new Response(); |
161
|
|
|
|
162
|
1 |
|
$httpCache = $this->getHttpCachePartialMock(['lookup']); |
163
|
1 |
|
$testListener = new TestListener($this, $httpCache, $request); |
|
|
|
|
164
|
1 |
|
$testListener->postHandleResponse = $postResponse; |
165
|
1 |
|
$httpCache->addSubscriber($testListener); |
|
|
|
|
166
|
|
|
$httpCache |
|
|
|
|
167
|
1 |
|
->expects($this->any()) |
168
|
1 |
|
->method('lookup') |
169
|
1 |
|
->with($request) |
170
|
1 |
|
->will($this->returnValue($regularResponse)) |
171
|
|
|
; |
172
|
|
|
|
173
|
1 |
|
$this->assertSame($postResponse, $httpCache->handle($request, HttpKernelInterface::MASTER_REQUEST, $catch)); |
|
|
|
|
174
|
1 |
|
$this->assertEquals(1, $testListener->preHandleCalls); |
175
|
1 |
|
$this->assertEquals(1, $testListener->postHandleCalls); |
176
|
1 |
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Assert that postHandle is called and the response can be updated even when preHandle returned a response. |
180
|
|
|
* |
181
|
|
|
* @depends testHandleCalled |
182
|
|
|
*/ |
183
|
1 |
|
public function testPostHandleAfterPreHandle() |
184
|
|
|
{ |
185
|
1 |
|
$catch = true; |
186
|
1 |
|
$request = Request::create('/foo', 'GET'); |
187
|
1 |
|
$preResponse = new Response(); |
188
|
1 |
|
$postResponse = new Response(); |
189
|
|
|
|
190
|
1 |
|
$httpCache = $this->getHttpCachePartialMock(['lookup']); |
191
|
1 |
|
$testListener = new TestListener($this, $httpCache, $request); |
|
|
|
|
192
|
1 |
|
$testListener->preHandleResponse = $preResponse; |
193
|
1 |
|
$testListener->postHandleResponse = $postResponse; |
194
|
1 |
|
$httpCache->addSubscriber($testListener); |
|
|
|
|
195
|
|
|
$httpCache |
|
|
|
|
196
|
1 |
|
->expects($this->never()) |
197
|
1 |
|
->method('lookup') |
198
|
|
|
; |
199
|
|
|
|
200
|
1 |
|
$this->assertSame($postResponse, $httpCache->handle($request, HttpKernelInterface::MASTER_REQUEST, $catch)); |
|
|
|
|
201
|
1 |
|
$this->assertEquals(1, $testListener->preHandleCalls); |
202
|
1 |
|
$this->assertEquals(1, $testListener->postHandleCalls); |
203
|
1 |
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Assert that preStore is called. |
207
|
|
|
*/ |
208
|
1 |
|
public function testPreStoreCalled() |
209
|
|
|
{ |
210
|
1 |
|
$request = Request::create('/foo', 'GET'); |
211
|
1 |
|
$response = new Response(); |
212
|
|
|
|
213
|
1 |
|
$httpCache = $this->getHttpCachePartialMock(); |
214
|
1 |
|
$testListener = new TestListener($this, $httpCache, $request); |
|
|
|
|
215
|
1 |
|
$httpCache->addSubscriber($testListener); |
|
|
|
|
216
|
|
|
|
217
|
1 |
|
$this->setStoreMock($httpCache, $request, $response); |
|
|
|
|
218
|
|
|
|
219
|
1 |
|
$refHttpCache = new \ReflectionObject($httpCache); |
220
|
1 |
|
$method = $refHttpCache->getMethod('store'); |
221
|
1 |
|
$method->setAccessible(true); |
222
|
1 |
|
$method->invokeArgs($httpCache, [$request, $response]); |
223
|
1 |
|
$this->assertEquals(1, $testListener->preStoreCalls); |
224
|
1 |
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Assert that preStore response is used when provided. |
228
|
|
|
*/ |
229
|
1 |
|
public function testPreStoreResponse() |
230
|
|
|
{ |
231
|
1 |
|
$request = Request::create('/foo', 'GET'); |
232
|
1 |
|
$regularResponse = new Response(); |
233
|
1 |
|
$preStoreResponse = new Response(); |
234
|
|
|
|
235
|
1 |
|
$httpCache = $this->getHttpCachePartialMock(); |
236
|
1 |
|
$testListener = new TestListener($this, $httpCache, $request); |
|
|
|
|
237
|
1 |
|
$testListener->preStoreResponse = $preStoreResponse; |
238
|
1 |
|
$httpCache->addSubscriber($testListener); |
|
|
|
|
239
|
|
|
|
240
|
1 |
|
$this->setStoreMock($httpCache, $request, $preStoreResponse); |
|
|
|
|
241
|
|
|
|
242
|
1 |
|
$refHttpCache = new \ReflectionObject($httpCache); |
243
|
1 |
|
$method = $refHttpCache->getMethod('store'); |
244
|
1 |
|
$method->setAccessible(true); |
245
|
1 |
|
$method->invokeArgs($httpCache, [$request, $regularResponse]); |
246
|
1 |
|
$this->assertEquals(1, $testListener->preStoreCalls); |
247
|
1 |
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* Assert that preInvalidate is called. |
251
|
|
|
*/ |
252
|
1 |
|
public function testPreInvalidateCalled() |
253
|
|
|
{ |
254
|
1 |
|
$catch = true; |
255
|
1 |
|
$request = Request::create('/foo', 'GET'); |
256
|
1 |
|
$response = new Response('', 500); |
257
|
|
|
|
258
|
1 |
|
$httpCache = $this->getHttpCachePartialMock(['pass']); |
259
|
1 |
|
$testListener = new TestListener($this, $httpCache, $request); |
|
|
|
|
260
|
1 |
|
$httpCache->addSubscriber($testListener); |
|
|
|
|
261
|
|
|
$httpCache |
|
|
|
|
262
|
1 |
|
->expects($this->any()) |
263
|
1 |
|
->method('pass') |
264
|
1 |
|
->with($request) |
265
|
1 |
|
->will($this->returnValue($response)) |
266
|
|
|
; |
267
|
1 |
|
$refHttpCache = new \ReflectionObject($httpCache); |
268
|
1 |
|
$method = $refHttpCache->getMethod('invalidate'); |
269
|
1 |
|
$method->setAccessible(true); |
270
|
|
|
|
271
|
1 |
|
$this->assertSame($response, $method->invokeArgs($httpCache, [$request, $catch])); |
272
|
1 |
|
$this->assertEquals(1, $testListener->preInvalidateCalls); |
273
|
1 |
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Assert that when preInvalidate returns a response, that response is used and the normal kernel flow stopped. |
277
|
|
|
* |
278
|
|
|
* @depends testPreInvalidateCalled |
279
|
|
|
*/ |
280
|
1 |
|
public function testPreInvalidateReturnEarly() |
281
|
|
|
{ |
282
|
1 |
|
$catch = true; |
283
|
1 |
|
$request = Request::create('/foo', 'GET'); |
284
|
1 |
|
$response = new Response('', 400); |
285
|
|
|
|
286
|
1 |
|
$httpCache = $this->getHttpCachePartialMock(['pass']); |
287
|
1 |
|
$testListener = new TestListener($this, $httpCache, $request); |
|
|
|
|
288
|
1 |
|
$testListener->preInvalidateResponse = $response; |
289
|
1 |
|
$httpCache->addSubscriber($testListener); |
|
|
|
|
290
|
|
|
$httpCache |
|
|
|
|
291
|
1 |
|
->expects($this->never()) |
292
|
1 |
|
->method('pass') |
293
|
|
|
; |
294
|
1 |
|
$refHttpCache = new \ReflectionObject($httpCache); |
295
|
1 |
|
$method = $refHttpCache->getMethod('invalidate'); |
296
|
1 |
|
$method->setAccessible(true); |
297
|
|
|
|
298
|
1 |
|
$this->assertSame($response, $method->invokeArgs($httpCache, [$request, $catch])); |
299
|
1 |
|
$this->assertEquals(1, $testListener->preInvalidateCalls); |
300
|
1 |
|
} |
301
|
|
|
|
302
|
1 |
|
public function testAddListener() |
303
|
|
|
{ |
304
|
1 |
|
$request = Request::create('/foo', 'GET'); |
305
|
1 |
|
$response = new Response(); |
306
|
|
|
|
307
|
1 |
|
$httpCache = $this->getHttpCachePartialMock(['lookup']); |
308
|
1 |
|
$simpleListener = new SimpleListener($this, $httpCache, $request); |
|
|
|
|
309
|
1 |
|
$httpCache->addListener(Events::PRE_HANDLE, [$simpleListener, 'callback']); |
|
|
|
|
310
|
|
|
|
311
|
|
|
$httpCache |
|
|
|
|
312
|
1 |
|
->expects($this->any()) |
313
|
1 |
|
->method('lookup') |
314
|
1 |
|
->with($request) |
315
|
1 |
|
->will($this->returnValue($response)) |
316
|
|
|
; |
317
|
|
|
|
318
|
1 |
|
$this->assertSame($response, $httpCache->handle($request, HttpKernelInterface::MASTER_REQUEST)); |
|
|
|
|
319
|
1 |
|
$this->assertEquals(1, $simpleListener->calls); |
320
|
1 |
|
} |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
class TestListener implements EventSubscriberInterface |
|
|
|
|
324
|
|
|
{ |
325
|
|
|
/** |
326
|
|
|
* @var int Count how many times preHandle has been called |
327
|
|
|
*/ |
328
|
|
|
public $preHandleCalls = 0; |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* @var int Count how many times postHandle has been called |
332
|
|
|
*/ |
333
|
|
|
public $postHandleCalls = 0; |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* @var int Count how many times preStore has been called |
337
|
|
|
*/ |
338
|
|
|
public $preStoreCalls = 0; |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* @var int Count how many times preInvalidate has been called |
342
|
|
|
*/ |
343
|
|
|
public $preInvalidateCalls = 0; |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* @var Response A response to set during the preHandle |
347
|
|
|
*/ |
348
|
|
|
public $preHandleResponse; |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* @var Response A response to set during the postHandle |
352
|
|
|
*/ |
353
|
|
|
public $postHandleResponse; |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* @var Response A response to set during the preStore |
357
|
|
|
*/ |
358
|
|
|
public $preStoreResponse; |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* @var Response A response to set during the preInvalidate |
362
|
|
|
*/ |
363
|
|
|
public $preInvalidateResponse; |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* @var EventDispatchingHttpCacheTestCase To do assertions |
367
|
|
|
*/ |
368
|
|
|
private $test; |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* @var CacheInvalidation The kernel to ensure the event carries the correct kernel |
372
|
|
|
*/ |
373
|
|
|
private $kernel; |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* @var Request The request to ensure the event carries the correct request |
377
|
|
|
*/ |
378
|
|
|
private $request; |
379
|
|
|
|
380
|
8 |
|
public function __construct( |
381
|
|
|
EventDispatchingHttpCacheTestCase $test, |
382
|
|
|
CacheInvalidation $kernel, |
383
|
|
|
Request $request |
|
|
|
|
384
|
|
|
) { |
385
|
8 |
|
$this->test = $test; |
386
|
8 |
|
$this->kernel = $kernel; |
387
|
8 |
|
$this->request = $request; |
388
|
8 |
|
} |
389
|
|
|
|
390
|
8 |
|
public static function getSubscribedEvents() |
391
|
|
|
{ |
392
|
|
|
return [ |
393
|
8 |
|
Events::PRE_HANDLE => 'preHandle', |
394
|
8 |
|
Events::POST_HANDLE => 'postHandle', |
395
|
8 |
|
Events::PRE_STORE => 'preStore', |
396
|
8 |
|
Events::PRE_INVALIDATE => 'preInvalidate', |
397
|
|
|
]; |
398
|
|
|
} |
399
|
|
|
|
400
|
4 |
View Code Duplication |
public function preHandle(CacheEvent $event) |
|
|
|
|
401
|
|
|
{ |
402
|
4 |
|
$this->test->assertSame($this->kernel, $event->getKernel()); |
403
|
4 |
|
$this->test->assertSame($this->request, $event->getRequest()); |
404
|
4 |
|
if ($this->preHandleResponse) { |
405
|
2 |
|
$event->setResponse($this->preHandleResponse); |
406
|
|
|
} |
407
|
4 |
|
++$this->preHandleCalls; |
408
|
4 |
|
} |
409
|
|
|
|
410
|
4 |
View Code Duplication |
public function postHandle(CacheEvent $event) |
|
|
|
|
411
|
|
|
{ |
412
|
4 |
|
$this->test->assertSame($this->kernel, $event->getKernel()); |
413
|
4 |
|
$this->test->assertSame($this->request, $event->getRequest()); |
414
|
4 |
|
if ($this->postHandleResponse) { |
415
|
2 |
|
$event->setResponse($this->postHandleResponse); |
416
|
|
|
} |
417
|
4 |
|
++$this->postHandleCalls; |
418
|
4 |
|
} |
419
|
|
|
|
420
|
2 |
View Code Duplication |
public function preStore(CacheEvent $event) |
|
|
|
|
421
|
|
|
{ |
422
|
2 |
|
$this->test->assertSame($this->kernel, $event->getKernel()); |
423
|
2 |
|
$this->test->assertSame($this->request, $event->getRequest()); |
424
|
2 |
|
if ($this->preStoreResponse) { |
425
|
1 |
|
$event->setResponse($this->preStoreResponse); |
426
|
|
|
} |
427
|
2 |
|
++$this->preStoreCalls; |
428
|
2 |
|
} |
429
|
|
|
|
430
|
2 |
View Code Duplication |
public function preInvalidate(CacheEvent $event) |
|
|
|
|
431
|
|
|
{ |
432
|
2 |
|
$this->test->assertSame($this->kernel, $event->getKernel()); |
433
|
2 |
|
$this->test->assertSame($this->request, $event->getRequest()); |
434
|
2 |
|
if ($this->preInvalidateResponse) { |
435
|
1 |
|
$event->setResponse($this->preInvalidateResponse); |
436
|
|
|
} |
437
|
2 |
|
++$this->preInvalidateCalls; |
438
|
2 |
|
} |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
class SimpleListener |
|
|
|
|
442
|
|
|
{ |
443
|
|
|
public $calls = 0; |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* @var EventDispatchingHttpCacheTestCase To do assertions |
447
|
|
|
*/ |
448
|
|
|
private $test; |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* @var CacheInvalidation The kernel to ensure the event carries the correct kernel |
452
|
|
|
*/ |
453
|
|
|
private $kernel; |
454
|
|
|
|
455
|
|
|
/** |
456
|
|
|
* @var Request The request to ensure the event carries the correct request |
457
|
|
|
*/ |
458
|
|
|
private $request; |
459
|
|
|
|
460
|
1 |
|
public function __construct( |
461
|
|
|
EventDispatchingHttpCacheTestCase $test, |
462
|
|
|
CacheInvalidation $kernel, |
463
|
|
|
Request $request |
|
|
|
|
464
|
|
|
) { |
465
|
1 |
|
$this->test = $test; |
466
|
1 |
|
$this->kernel = $kernel; |
467
|
1 |
|
$this->request = $request; |
468
|
1 |
|
} |
469
|
|
|
|
470
|
1 |
|
public function callback(CacheEvent $event) |
471
|
|
|
{ |
472
|
1 |
|
$this->test->assertSame($this->kernel, $event->getKernel()); |
473
|
1 |
|
$this->test->assertSame($this->request, $event->getRequest()); |
474
|
1 |
|
++$this->calls; |
475
|
1 |
|
} |
476
|
|
|
} |
477
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.