This repository was archived by the owner on Jan 29, 2020. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathStorageFactoryTest.php
More file actions
209 lines (178 loc) · 6.67 KB
/
Copy pathStorageFactoryTest.php
File metadata and controls
209 lines (178 loc) · 6.67 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace ZendTest\Cache;
use PHPUnit\Framework\TestCase;
use Zend\Cache;
use Zend\ServiceManager\ServiceManager;
/**
* @group Zend_Cache
* @covers Zend\Cache\StorageFactory
*/
class StorageFactoryTest extends TestCase
{
public function setUp()
{
Cache\StorageFactory::resetAdapterPluginManager();
Cache\StorageFactory::resetPluginManager();
}
public function tearDown()
{
Cache\StorageFactory::resetAdapterPluginManager();
Cache\StorageFactory::resetPluginManager();
}
public function testDefaultAdapterPluginManager()
{
$adapters = Cache\StorageFactory::getAdapterPluginManager();
$this->assertInstanceOf('Zend\Cache\Storage\AdapterPluginManager', $adapters);
}
public function testChangeAdapterPluginManager()
{
$adapters = new Cache\Storage\AdapterPluginManager(new ServiceManager);
Cache\StorageFactory::setAdapterPluginManager($adapters);
$this->assertSame($adapters, Cache\StorageFactory::getAdapterPluginManager());
}
public function testAdapterFactory()
{
$adapter1 = Cache\StorageFactory::adapterFactory('Memory');
$this->assertInstanceOf('Zend\Cache\Storage\Adapter\Memory', $adapter1);
$adapter2 = Cache\StorageFactory::adapterFactory('Memory');
$this->assertInstanceOf('Zend\Cache\Storage\Adapter\Memory', $adapter2);
$this->assertNotSame($adapter1, $adapter2);
}
public function testDefaultPluginManager()
{
$manager = Cache\StorageFactory::getPluginManager();
$this->assertInstanceOf('Zend\Cache\Storage\PluginManager', $manager);
}
public function testChangePluginManager()
{
$manager = new Cache\Storage\PluginManager(new ServiceManager);
Cache\StorageFactory::setPluginManager($manager);
$this->assertSame($manager, Cache\StorageFactory::getPluginManager());
}
public function testPluginFactory()
{
$plugin1 = Cache\StorageFactory::pluginFactory('Serializer');
$this->assertInstanceOf('Zend\Cache\Storage\Plugin\Serializer', $plugin1);
$plugin2 = Cache\StorageFactory::pluginFactory('Serializer');
$this->assertInstanceOf('Zend\Cache\Storage\Plugin\Serializer', $plugin2);
$this->assertNotSame($plugin1, $plugin2);
}
public function testFactoryAdapterAsString()
{
$cache = Cache\StorageFactory::factory([
'adapter' => 'Memory',
]);
$this->assertInstanceOf('Zend\Cache\Storage\Adapter\Memory', $cache);
}
/**
* @group 4445
*/
public function testFactoryWithAdapterAsStringAndOptions()
{
$cache = Cache\StorageFactory::factory([
'adapter' => 'Memory',
'options' => [
'namespace' => 'test'
],
]);
$this->assertInstanceOf('Zend\Cache\Storage\Adapter\Memory', $cache);
$this->assertSame('test', $cache->getOptions()->getNamespace());
}
public function testFactoryAdapterAsArray()
{
$cache = Cache\StorageFactory::factory([
'adapter' => [
'name' => 'Memory',
]
]);
$this->assertInstanceOf('Zend\Cache\Storage\Adapter\Memory', $cache);
}
public function testFactoryWithPlugins()
{
$adapter = 'Memory';
$plugins = ['Serializer', 'ClearExpiredByFactor'];
$cache = Cache\StorageFactory::factory([
'adapter' => $adapter,
'plugins' => $plugins,
]);
// test adapter
$this->assertInstanceOf('Zend\Cache\Storage\Adapter\Memory', $cache);
// test plugin structure
$i = 0;
foreach ($cache->getPluginRegistry() as $plugin) {
$this->assertInstanceOf('Zend\Cache\Storage\Plugin\\' . $plugins[$i++], $plugin);
}
}
public function testFactoryInstantiateAdapterWithPluginsWithoutEventsCapableInterfaceThrowsException()
{
// The BlackHole adapter doesn't implement EventsCapableInterface
$this->expectException('Zend\Cache\Exception\RuntimeException');
Cache\StorageFactory::factory([
'adapter' => 'blackhole',
'plugins' => ['Serializer'],
]);
}
public function testFactoryWithPluginsAndOptionsArray()
{
$factory = [
'adapter' => [
'name' => 'Memory',
'options' => [
'ttl' => 123,
'namespace' => 'willBeOverwritten'
],
],
'plugins' => [
// plugin as a simple string entry
'Serializer',
// plugin as name-options pair
'ClearExpiredByFactor' => [
'clearing_factor' => 1,
],
// plugin with full definition
[
'name' => 'IgnoreUserAbort',
'priority' => 100,
'options' => [
'exit_on_abort' => false,
],
],
],
'options' => [
'namespace' => 'test',
]
];
$storage = Cache\StorageFactory::factory($factory);
// test adapter
$this->assertInstanceOf('Zend\Cache\Storage\Adapter\\' . $factory['adapter']['name'], $storage);
$this->assertEquals(123, $storage->getOptions()->getTtl());
$this->assertEquals('test', $storage->getOptions()->getNamespace());
// test plugin structure
foreach ($storage->getPluginRegistry() as $plugin) {
// test plugin options
$pluginClass = get_class($plugin);
switch ($pluginClass) {
case 'Zend\Cache\Storage\Plugin\ClearExpiredByFactor':
$this->assertSame(
$factory['plugins']['ClearExpiredByFactor']['clearing_factor'],
$plugin->getOptions()->getClearingFactor()
);
break;
case 'Zend\Cache\Storage\Plugin\Serializer':
break;
case 'Zend\Cache\Storage\Plugin\IgnoreUserAbort':
$this->assertFalse($plugin->getOptions()->getExitOnAbort());
break;
default:
$this->fail("Unexpected plugin class '{$pluginClass}'");
}
}
}
}