|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the FOSHttpCacheBundle 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\HttpCacheBundle\Tests\Functional\EventListener; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
15
|
|
|
|
|
16
|
|
|
class InvalidationListenerTest extends WebTestCase |
|
17
|
|
|
{ |
|
18
|
|
|
public function testInvalidateRoute() |
|
19
|
|
|
{ |
|
20
|
|
|
$client = static::createClient(); |
|
21
|
|
|
|
|
22
|
|
|
$client->getContainer()->mock( |
|
|
|
|
|
|
23
|
|
|
'fos_http_cache.cache_manager', |
|
24
|
|
|
'\FOS\HttpCacheBundle\CacheManager' |
|
25
|
|
|
) |
|
26
|
|
|
->shouldReceive('supports')->andReturn(true) |
|
27
|
|
|
->shouldReceive('invalidateRoute')->once()->with('test_noncached', array()) |
|
28
|
|
|
->shouldReceive('invalidateRoute')->once()->with('test_cached', array('id' => 'myhardcodedid')) |
|
29
|
|
|
->shouldReceive('invalidateRoute')->once()->with('tag_one', array('id' => '42')) |
|
30
|
|
|
->shouldReceive('flush')->once() |
|
31
|
|
|
; |
|
32
|
|
|
|
|
33
|
|
|
$client->request('POST', '/invalidate/route/42'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @dataProvider getStatusCodesThatTriggerInvalidation |
|
38
|
|
|
*/ |
|
39
|
|
|
public function testInvalidatePath($statusCode) |
|
40
|
|
|
{ |
|
41
|
|
|
$client = static::createClient(); |
|
42
|
|
|
|
|
43
|
|
|
$client->getContainer()->mock( |
|
|
|
|
|
|
44
|
|
|
'fos_http_cache.cache_manager', |
|
45
|
|
|
'\FOS\HttpCacheBundle\CacheManager' |
|
46
|
|
|
) |
|
47
|
|
|
->shouldReceive('supports')->andReturn(true) |
|
48
|
|
|
->shouldReceive('invalidatePath')->once()->with('/cached') |
|
49
|
|
|
->shouldReceive('invalidatePath')->once()->with( |
|
50
|
|
|
sprintf('/invalidate/path/%s', $statusCode) |
|
51
|
|
|
) |
|
52
|
|
|
->shouldReceive('flush')->once() |
|
53
|
|
|
; |
|
54
|
|
|
|
|
55
|
|
|
$client->request('POST', sprintf('/invalidate/path/%s', $statusCode)); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
View Code Duplication |
public function testErrorIsNotInvalidated() |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
$client = static::createClient(); |
|
61
|
|
|
|
|
62
|
|
|
$client->getContainer()->mock( |
|
|
|
|
|
|
63
|
|
|
'fos_http_cache.cache_manager', |
|
64
|
|
|
'\FOS\HttpCacheBundle\CacheManager' |
|
65
|
|
|
) |
|
66
|
|
|
->shouldReceive('supports')->andReturn(true) |
|
67
|
|
|
->shouldReceive('invalidatePath')->never() |
|
68
|
|
|
->shouldReceive('flush')->once() |
|
69
|
|
|
; |
|
70
|
|
|
|
|
71
|
|
|
$client->request('POST', '/invalidate/error'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getStatusCodesThatTriggerInvalidation() |
|
75
|
|
|
{ |
|
76
|
|
|
return array(array(200), array(204), array(302)); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
protected function tearDown() |
|
80
|
|
|
{ |
|
81
|
|
|
static::createClient()->getContainer()->unmock('fos_http_cache.cache_manager'); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
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.