-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathPrefixedCachePoolTest.php
More file actions
153 lines (122 loc) · 4.66 KB
/
Copy pathPrefixedCachePoolTest.php
File metadata and controls
153 lines (122 loc) · 4.66 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
<?php
/*
* This file is part of php-cache organization.
*
* (c) 2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Cache\Prefixed\Tests;
use Cache\Prefixed\PrefixedCachePool;
use PHPUnit\Framework\TestCase;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
class PrefixedCachePoolTest extends TestCase
{
/**
* @return \PHPUnit_Framework_MockObject_MockObject|CacheItemPoolInterface
*/
private function getCacheStub()
{
return $this->getMockBuilder(CacheItemPoolInterface::class)->setMethods(
['getItem', 'getItems', 'hasItem', 'clear', 'deleteItem', 'deleteItems', 'save', 'saveDeferred', 'commit']
)->getMock();
}
public function testGetItem()
{
$prefix = 'ns';
$key = 'key';
$returnValue = true;
$stub = $this->getCacheStub();
$stub->expects($this->once())->method('getItem')->with($prefix.$key)->willReturn($returnValue);
$pool = new PrefixedCachePool($stub, $prefix);
$this->assertEquals($returnValue, $pool->getItem($key));
}
public function testGetItems()
{
$prefix = 'ns';
$key0 = 'key0';
$key1 = 'key1';
$returnValue = true;
$stub = $this->getCacheStub();
$stub->expects($this->once())->method('getItems')->with([$prefix.$key0, $prefix.$key1])->willReturn($returnValue);
$pool = new PrefixedCachePool($stub, $prefix);
$this->assertEquals($returnValue, $pool->getItems([$key0, $key1]));
}
public function testHasItem()
{
$prefix = 'ns';
$key = 'key';
$returnValue = true;
$stub = $this->getCacheStub();
$stub->expects($this->once())->method('hasItem')->with($prefix.$key)->willReturn($returnValue);
$pool = new PrefixedCachePool($stub, $prefix);
$this->assertEquals($returnValue, $pool->hasItem($key));
}
public function testClear()
{
$prefix = 'ns';
$key = 'key';
$returnValue = true;
$stub = $this->getCacheStub();
$stub->expects($this->once())->method('clear')->willReturn($returnValue);
$pool = new PrefixedCachePool($stub, $prefix);
$this->assertEquals($returnValue, $pool->clear());
}
public function testDeleteItem()
{
$prefix = 'ns';
$key = 'key';
$returnValue = true;
$stub = $this->getCacheStub();
$stub->expects($this->once())->method('deleteItem')->with($prefix.$key)->willReturn($returnValue);
$pool = new PrefixedCachePool($stub, $prefix);
$this->assertEquals($returnValue, $pool->deleteItem($key));
}
public function testDeleteItems()
{
$prefix = 'ns';
$key0 = 'key0';
$key1 = 'key1';
$returnValue = true;
$stub = $this->getCacheStub();
$stub->expects($this->once())->method('deleteItems')->with([$prefix.$key0, $prefix.$key1])->willReturn($returnValue);
$pool = new PrefixedCachePool($stub, $prefix);
$this->assertEquals($returnValue, $pool->deleteItems([$key0, $key1]));
}
public function testSave()
{
/** @type CacheItemInterface $item */
$item = $this->getMockBuilder(CacheItemInterface::class)->getMock();
$prefix = 'ns';
$returnValue = true;
$stub = $this->getCacheStub();
$stub->expects($this->once())->method('save')->with($item)->willReturn($returnValue);
$pool = new PrefixedCachePool($stub, $prefix);
$this->assertEquals($returnValue, $pool->save($item));
}
public function testSaveDeffered()
{
/** @type CacheItemInterface $item */
$item = $this->getMockBuilder(CacheItemInterface::class)->getMock();
$prefix = 'ns';
$returnValue = true;
$stub = $this->getCacheStub();
$stub->expects($this->once())->method('saveDeferred')->with($item)->willReturn($returnValue);
$pool = new PrefixedCachePool($stub, $prefix);
$this->assertEquals($returnValue, $pool->saveDeferred($item));
}
public function testCommit()
{
$prefix = 'ns';
$returnValue = true;
$stub = $this->getCacheStub();
$stub->expects($this->once())->method('commit')->willReturn($returnValue);
$pool = new PrefixedCachePool($stub, $prefix);
$this->assertEquals($returnValue, $pool->commit());
}
}