|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\Common\Cache; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Cache\CacheProvider; |
|
6
|
|
|
|
|
7
|
|
|
class CacheProviderTest extends \Doctrine\Tests\DoctrineTestCase |
|
8
|
|
|
{ |
|
9
|
|
|
public function testFetchMultiWillFilterNonRequestedKeys() |
|
10
|
|
|
{ |
|
11
|
|
|
/* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */ |
|
12
|
|
|
$cache = $this->getMockForAbstractClass( |
|
13
|
|
|
'Doctrine\Common\Cache\CacheProvider', |
|
14
|
|
|
[], |
|
15
|
|
|
'', |
|
16
|
|
|
true, |
|
17
|
|
|
true, |
|
18
|
|
|
true, |
|
19
|
|
|
['doFetchMultiple'] |
|
20
|
|
|
); |
|
21
|
|
|
|
|
22
|
|
|
$cache |
|
23
|
|
|
->expects($this->once()) |
|
24
|
|
|
->method('doFetchMultiple') |
|
25
|
|
|
->will($this->returnValue([ |
|
26
|
|
|
'[foo][1]' => 'bar', |
|
27
|
|
|
'[bar][1]' => 'baz', |
|
28
|
|
|
'[baz][1]' => 'tab', |
|
29
|
|
|
])); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertEquals( |
|
32
|
|
|
['foo' => 'bar', 'bar' => 'baz'], |
|
33
|
|
|
$cache->fetchMultiple(['foo', 'bar']) |
|
34
|
|
|
); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testFailedDeleteAllDoesNotChangeNamespaceVersion() |
|
38
|
|
|
{ |
|
39
|
|
|
/* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */ |
|
40
|
|
|
$cache = $this->getMockForAbstractClass( |
|
41
|
|
|
'Doctrine\Common\Cache\CacheProvider', |
|
42
|
|
|
[], |
|
43
|
|
|
'', |
|
44
|
|
|
true, |
|
45
|
|
|
true, |
|
46
|
|
|
true, |
|
47
|
|
|
['doFetch', 'doSave', 'doContains'] |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
|
|
$cache |
|
51
|
|
|
->expects($this->once()) |
|
52
|
|
|
->method('doFetch') |
|
53
|
|
|
->with('DoctrineNamespaceCacheKey[]') |
|
54
|
|
|
->will($this->returnValue(false)); |
|
55
|
|
|
|
|
56
|
|
|
// doSave is only called once from deleteAll as we do not need to persist the default version in getNamespaceVersion() |
|
57
|
|
|
$cache |
|
58
|
|
|
->expects($this->once()) |
|
59
|
|
|
->method('doSave') |
|
60
|
|
|
->with('DoctrineNamespaceCacheKey[]') |
|
61
|
|
|
->will($this->returnValue(false)); |
|
62
|
|
|
|
|
63
|
|
|
// After a failed deleteAll() the local namespace version is not increased (still 1). Otherwise all data written afterwards |
|
64
|
|
|
// would be lost outside the current instance. |
|
65
|
|
|
$cache |
|
66
|
|
|
->expects($this->once()) |
|
67
|
|
|
->method('doContains') |
|
68
|
|
|
->with('[key][1]') |
|
69
|
|
|
->will($this->returnValue(true)); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertFalse($cache->deleteAll(), 'deleteAll() returns false when saving the namespace version fails'); |
|
72
|
|
|
$cache->contains('key'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function testSaveMultipleNoFail() |
|
76
|
|
|
{ |
|
77
|
|
|
/* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */ |
|
78
|
|
|
$cache = $this->getMockForAbstractClass( |
|
79
|
|
|
'Doctrine\Common\Cache\CacheProvider', |
|
80
|
|
|
[], |
|
81
|
|
|
'', |
|
82
|
|
|
true, |
|
83
|
|
|
true, |
|
84
|
|
|
true, |
|
85
|
|
|
['doSave'] |
|
86
|
|
|
); |
|
87
|
|
|
|
|
88
|
|
|
$cache |
|
89
|
|
|
->expects($this->at(1)) |
|
90
|
|
|
->method('doSave') |
|
91
|
|
|
->with('[kerr][1]', 'verr', 0) |
|
92
|
|
|
->will($this->returnValue(false)); |
|
93
|
|
|
|
|
94
|
|
|
$cache |
|
95
|
|
|
->expects($this->at(2)) |
|
96
|
|
|
->method('doSave') |
|
97
|
|
|
->with('[kok][1]', 'vok', 0) |
|
98
|
|
|
->will($this->returnValue(true)); |
|
99
|
|
|
|
|
100
|
|
|
$cache->saveMultiple([ |
|
101
|
|
|
'kerr' => 'verr', |
|
102
|
|
|
'kok' => 'vok', |
|
103
|
|
|
]); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function testDeleteMultipleNoFail() |
|
107
|
|
|
{ |
|
108
|
|
|
/* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */ |
|
109
|
|
|
$cache = $this |
|
110
|
|
|
->getMockBuilder(CacheProvider::class) |
|
111
|
|
|
->setMethods(['doDelete']) |
|
112
|
|
|
->getMockForAbstractClass(); |
|
113
|
|
|
|
|
114
|
|
|
$cache |
|
115
|
|
|
->expects($this->at(1)) |
|
116
|
|
|
->method('doDelete') |
|
117
|
|
|
->with('[kerr][1]') |
|
118
|
|
|
->will($this->returnValue(false)); |
|
119
|
|
|
|
|
120
|
|
|
$cache |
|
121
|
|
|
->expects($this->at(2)) |
|
122
|
|
|
->method('doDelete') |
|
123
|
|
|
->with('[kok][1]') |
|
124
|
|
|
->will($this->returnValue(true)); |
|
125
|
|
|
|
|
126
|
|
|
$cache->deleteMultiple(['kerr', 'kok']); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|