|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\Common\Cache; |
|
4
|
|
|
|
|
5
|
|
|
class CacheProviderTest extends \Doctrine\Tests\DoctrineTestCase |
|
6
|
|
|
{ |
|
7
|
|
|
public function testFetchMultiWillFilterNonRequestedKeys() |
|
8
|
|
|
{ |
|
9
|
|
|
/* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */ |
|
10
|
|
|
$cache = $this->getMockForAbstractClass( |
|
11
|
|
|
'Doctrine\Common\Cache\CacheProvider', |
|
12
|
|
|
array(), |
|
13
|
|
|
'', |
|
14
|
|
|
true, |
|
15
|
|
|
true, |
|
16
|
|
|
true, |
|
17
|
|
|
array('doFetchMultiple') |
|
18
|
|
|
); |
|
19
|
|
|
|
|
20
|
|
|
$cache |
|
|
|
|
|
|
21
|
|
|
->expects($this->once()) |
|
22
|
|
|
->method('doFetchMultiple') |
|
23
|
|
|
->will($this->returnValue(array( |
|
24
|
|
|
'[foo][1]' => 'bar', |
|
25
|
|
|
'[bar][1]' => 'baz', |
|
26
|
|
|
'[baz][1]' => 'tab', |
|
27
|
|
|
))); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertEquals( |
|
30
|
|
|
array('foo' => 'bar', 'bar' => 'baz'), |
|
31
|
|
|
$cache->fetchMultiple(array('foo', 'bar')) |
|
|
|
|
|
|
32
|
|
|
); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testFailedDeleteAllDoesNotChangeNamespaceVersion() |
|
36
|
|
|
{ |
|
37
|
|
|
/* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */ |
|
38
|
|
|
$cache = $this->getMockForAbstractClass( |
|
39
|
|
|
'Doctrine\Common\Cache\CacheProvider', |
|
40
|
|
|
array(), |
|
41
|
|
|
'', |
|
42
|
|
|
true, |
|
43
|
|
|
true, |
|
44
|
|
|
true, |
|
45
|
|
|
array('doFetch', 'doSave', 'doContains') |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
|
|
$cache |
|
|
|
|
|
|
49
|
|
|
->expects($this->once()) |
|
50
|
|
|
->method('doFetch') |
|
51
|
|
|
->with('DoctrineNamespaceCacheKey[]') |
|
52
|
|
|
->will($this->returnValue(false)); |
|
53
|
|
|
|
|
54
|
|
|
// doSave is only called once from deleteAll as we do not need to persist the default version in getNamespaceVersion() |
|
55
|
|
|
$cache |
|
56
|
|
|
->expects($this->once()) |
|
57
|
|
|
->method('doSave') |
|
58
|
|
|
->with('DoctrineNamespaceCacheKey[]') |
|
59
|
|
|
->will($this->returnValue(false)); |
|
60
|
|
|
|
|
61
|
|
|
// After a failed deleteAll() the local namespace version is not increased (still 1). Otherwise all data written afterwards |
|
62
|
|
|
// would be lost outside the current instance. |
|
63
|
|
|
$cache |
|
64
|
|
|
->expects($this->once()) |
|
65
|
|
|
->method('doContains') |
|
66
|
|
|
->with('[key][1]') |
|
67
|
|
|
->will($this->returnValue(true)); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertFalse($cache->deleteAll(), 'deleteAll() returns false when saving the namespace version fails'); |
|
|
|
|
|
|
70
|
|
|
$cache->contains('key'); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testSaveMultipleNoFail() |
|
74
|
|
|
{ |
|
75
|
|
|
/* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */ |
|
76
|
|
|
$cache = $this->getMockForAbstractClass( |
|
77
|
|
|
'Doctrine\Common\Cache\CacheProvider', |
|
78
|
|
|
array(), |
|
79
|
|
|
'', |
|
80
|
|
|
true, |
|
81
|
|
|
true, |
|
82
|
|
|
true, |
|
83
|
|
|
array('doSave') |
|
84
|
|
|
); |
|
85
|
|
|
|
|
86
|
|
|
$cache |
|
|
|
|
|
|
87
|
|
|
->expects($this->at(1)) |
|
88
|
|
|
->method('doSave') |
|
89
|
|
|
->with('[kerr][1]', 'verr', 0) |
|
90
|
|
|
->will($this->returnValue(false)); |
|
91
|
|
|
|
|
92
|
|
|
$cache |
|
93
|
|
|
->expects($this->at(2)) |
|
94
|
|
|
->method('doSave') |
|
95
|
|
|
->with('[kok][1]', 'vok', 0) |
|
96
|
|
|
->will($this->returnValue(true)); |
|
97
|
|
|
|
|
98
|
|
|
$cache->saveMultiple(array( |
|
|
|
|
|
|
99
|
|
|
'kerr' => 'verr', |
|
100
|
|
|
'kok' => 'vok', |
|
101
|
|
|
)); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: