1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AssetManagerTest\Cache; |
4
|
|
|
|
5
|
|
|
use AssetManager\Cache\ZendCacheAdapter; |
6
|
|
|
use Zend\Cache\Storage\Adapter\Memory; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Test file for Zend Cache Adapter |
10
|
|
|
* |
11
|
|
|
* @package AssetManager\Cache |
12
|
|
|
*/ |
13
|
|
|
class ZendCacheAdapterTest extends \PHPUnit_Framework_TestCase |
14
|
|
|
{ |
15
|
|
|
public function testConstructor() |
16
|
|
|
{ |
17
|
|
|
$mockZendCache = $this->getMockBuilder(Memory::class) |
18
|
|
|
->disableOriginalConstructor() |
19
|
|
|
->getMock(); |
20
|
|
|
|
21
|
|
|
$adapter = new ZendCacheAdapter($mockZendCache); |
22
|
|
|
|
23
|
|
|
$this->assertInstanceOf(ZendCacheAdapter::class, $adapter); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @expectedException \PHPUnit_Framework_Error |
28
|
|
|
*/ |
29
|
|
|
public function testConstructorOnlyAcceptsAZendCacheStorageInterface() |
30
|
|
|
{ |
31
|
|
|
if (PHP_MAJOR_VERSION >= 7) { |
32
|
|
|
$this->setExpectedException('\TypeError'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
new ZendCacheAdapter(new \DateTime()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testHasMethodCallsZendCacheHasItem() |
39
|
|
|
{ |
40
|
|
|
$mockZendCache = $this->getMockBuilder(Memory::class) |
41
|
|
|
->disableOriginalConstructor() |
42
|
|
|
->getMock(); |
43
|
|
|
|
44
|
|
|
$mockZendCache->expects($this->once()) |
45
|
|
|
->method('hasItem'); |
46
|
|
|
|
47
|
|
|
$adapter = new ZendCacheAdapter($mockZendCache); |
48
|
|
|
$adapter->has('SomeKey'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testGetMethodCallsZendCacheGetItem() |
52
|
|
|
{ |
53
|
|
|
$mockZendCache = $this->getMockBuilder(Memory::class) |
54
|
|
|
->disableOriginalConstructor() |
55
|
|
|
->getMock(); |
56
|
|
|
|
57
|
|
|
$mockZendCache->expects($this->once()) |
58
|
|
|
->method('getItem'); |
59
|
|
|
|
60
|
|
|
$adapter = new ZendCacheAdapter($mockZendCache); |
61
|
|
|
$adapter->get('SomeKey'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testSetMethodCallsZendCacheSetItem() |
65
|
|
|
{ |
66
|
|
|
$mockZendCache = $this->getMockBuilder(Memory::class) |
67
|
|
|
->disableOriginalConstructor() |
68
|
|
|
->getMock(); |
69
|
|
|
|
70
|
|
|
$mockZendCache->expects($this->once()) |
71
|
|
|
->method('setItem'); |
72
|
|
|
|
73
|
|
|
$adapter = new ZendCacheAdapter($mockZendCache); |
74
|
|
|
$adapter->set('SomeKey', array()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testRemoveMethodCallsZendCacheRemoveItem() |
78
|
|
|
{ |
79
|
|
|
$mockZendCache = $this->getMockBuilder(Memory::class) |
80
|
|
|
->disableOriginalConstructor() |
81
|
|
|
->getMock(); |
82
|
|
|
|
83
|
|
|
$mockZendCache->expects($this->once()) |
84
|
|
|
->method('removeItem'); |
85
|
|
|
|
86
|
|
|
$adapter = new ZendCacheAdapter($mockZendCache); |
87
|
|
|
$adapter->remove('SomeKey'); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|