1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Onoi\Cache\Tests; |
4
|
|
|
|
5
|
|
|
use Onoi\Cache\CacheFactory; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers \Onoi\Cache\CacheFactory |
9
|
|
|
* |
10
|
|
|
* @group onoi-cache |
11
|
|
|
* |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 1.0 |
14
|
|
|
* |
15
|
|
|
* @author mwjames |
16
|
|
|
*/ |
17
|
|
|
class CacheFactoryTest extends \PHPUnit_Framework_TestCase { |
18
|
|
|
|
19
|
|
|
public function testCanConstruct() { |
20
|
|
|
|
21
|
|
|
$this->assertInstanceOf( |
22
|
|
|
'\Onoi\Cache\CacheFactory', |
23
|
|
|
new CacheFactory() |
24
|
|
|
); |
25
|
|
|
|
26
|
|
|
$this->assertInstanceOf( |
27
|
|
|
'\Onoi\Cache\CacheFactory', |
28
|
|
|
CacheFactory::getInstance() |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testClear() { |
33
|
|
|
|
34
|
|
|
$instance = CacheFactory::getInstance(); |
35
|
|
|
|
36
|
|
|
$this->assertSame( |
37
|
|
|
$instance, |
38
|
|
|
CacheFactory::getInstance() |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
$instance->clear(); |
42
|
|
|
|
43
|
|
|
$this->assertNotSame( |
44
|
|
|
$instance, |
45
|
|
|
CacheFactory::getInstance() |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testCanConstructMediaWikiCache() { |
50
|
|
|
|
51
|
|
|
if ( !class_exists( '\BagOstuff' ) ) { |
52
|
|
|
$this->markTestSkipped( 'BagOstuff interface is not available' ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$cache = $this->getMockBuilder( '\BagOstuff' ) |
56
|
|
|
->disableOriginalConstructor() |
57
|
|
|
->getMockForAbstractClass(); |
58
|
|
|
|
59
|
|
|
$instance = new CacheFactory(); |
60
|
|
|
|
61
|
|
|
$this->assertInstanceOf( |
62
|
|
|
'\Onoi\Cache\MediaWikiCache', |
63
|
|
|
$instance->newMediaWikiCache( $cache ) |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testCanConstructDoctrineCache() { |
68
|
|
|
|
69
|
|
|
if ( !interface_exists( '\Doctrine\Common\Cache\Cache' ) ) { |
70
|
|
|
$this->markTestSkipped( 'Doctrine cache interface is not available' ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$cache = $this->getMockBuilder( '\Doctrine\Common\Cache\Cache' ) |
74
|
|
|
->disableOriginalConstructor() |
75
|
|
|
->getMockForAbstractClass(); |
76
|
|
|
|
77
|
|
|
$instance = new CacheFactory(); |
78
|
|
|
|
79
|
|
|
$this->assertInstanceOf( |
80
|
|
|
'\Onoi\Cache\DoctrineCache', |
81
|
|
|
$instance->newDoctrineCache( $cache ) |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testCanConstructFixedInMemoryLruCache() { |
86
|
|
|
|
87
|
|
|
$instance = new CacheFactory(); |
88
|
|
|
|
89
|
|
|
$this->assertInstanceOf( |
90
|
|
|
'\Onoi\Cache\FixedInMemoryLruCache', |
91
|
|
|
$instance->newFixedInMemoryLruCache( 1 ) |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
// Legacy |
95
|
|
|
$this->assertInstanceOf( |
96
|
|
|
'\Onoi\Cache\FixedInMemoryLruCache', |
97
|
|
|
$instance->newFixedInMemoryCache( 1 ) |
|
|
|
|
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testCanConstructCompositeCache() { |
102
|
|
|
|
103
|
|
|
$instance = new CacheFactory(); |
104
|
|
|
|
105
|
|
|
$cache = array( |
106
|
|
|
$instance->newFixedInMemoryCache() |
|
|
|
|
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$this->assertInstanceOf( |
110
|
|
|
'\Onoi\Cache\CompositeCache', |
111
|
|
|
$instance->newCompositeCache( $cache ) |
112
|
|
|
); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function testCanConstructNullCache() { |
116
|
|
|
|
117
|
|
|
$instance = new CacheFactory(); |
118
|
|
|
|
119
|
|
|
$this->assertInstanceOf( |
120
|
|
|
'\Onoi\Cache\NullCache', |
121
|
|
|
$instance->newNullCache() |
122
|
|
|
); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function testCanConstructZendCache() { |
126
|
|
|
|
127
|
|
|
if ( !interface_exists( '\Zend\Cache\Storage\StorageInterface' ) ) { |
128
|
|
|
$this->markTestSkipped( 'StorageInterface is not available' ); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$cache = $this->getMockBuilder( '\Zend\Cache\Storage\StorageInterface' ) |
132
|
|
|
->disableOriginalConstructor() |
133
|
|
|
->getMockForAbstractClass(); |
134
|
|
|
|
135
|
|
|
$instance = new CacheFactory(); |
136
|
|
|
|
137
|
|
|
$this->assertInstanceOf( |
138
|
|
|
'\Onoi\Cache\ZendCache', |
139
|
|
|
$instance->newZendCache( $cache ) |
140
|
|
|
); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
} |
144
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.