CacheProviderTest.php
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace Doctrine\Tests\Common\Cache;
class CacheProviderTest extends \Doctrine\Tests\DoctrineTestCase
{
public function testFetchMultiWillFilterNonRequestedKeys()
{
/* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */
$cache = $this->getMockForAbstractClass(
'Doctrine\Common\Cache\CacheProvider',
array(),
'',
true,
true,
true,
array('doFetchMultiple')
);
$cache
->expects($this->once())
->method('doFetchMultiple')
->will($this->returnValue(array(
'[foo][1]' => 'bar',
'[bar][1]' => 'baz',
'[baz][1]' => 'tab',
)));
$this->assertEquals(
array('foo' => 'bar', 'bar' => 'baz'),
$cache->fetchMultiple(array('foo', 'bar'))
);
}
public function testFailedDeleteAllDoesNotChangeNamespaceVersion()
{
/* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */
$cache = $this->getMockForAbstractClass(
'Doctrine\Common\Cache\CacheProvider',
array(),
'',
true,
true,
true,
array('doFetch', 'doSave', 'doContains')
);
$cache
->expects($this->once())
->method('doFetch')
->with('DoctrineNamespaceCacheKey[]')
->will($this->returnValue(false));
// doSave is only called once from deleteAll as we do not need to persist the default version in getNamespaceVersion()
$cache
->expects($this->once())
->method('doSave')
->with('DoctrineNamespaceCacheKey[]')
->will($this->returnValue(false));
// After a failed deleteAll() the local namespace version is not increased (still 1). Otherwise all data written afterwards
// would be lost outside the current instance.
$cache
->expects($this->once())
->method('doContains')
->with('[key][1]')
->will($this->returnValue(true));
$this->assertFalse($cache->deleteAll(), 'deleteAll() returns false when saving the namespace version fails');
$cache->contains('key');
}
}