1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Aimeos\MW\Cache; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
8
|
|
|
* @copyright Aimeos (aimeos.org), 2014 |
9
|
|
|
*/ |
10
|
|
|
class FlowTest extends \PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
private $object; |
13
|
|
|
private $mock; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Sets up the fixture, for example, opens a network connection. |
18
|
|
|
* This method is called before a test is executed. |
19
|
|
|
* |
20
|
|
|
* @access protected |
21
|
|
|
*/ |
22
|
|
|
protected function setUp() |
23
|
|
|
{ |
24
|
|
|
if( interface_exists( 'TYPO3\Flow\Cache\Frontend\FrontendInterface' ) === false ) { |
25
|
|
|
$this->markTestSkipped( 'Class \\TYPO3\\Flow\\Cache\\Frontend\\FrontendInterface not found' ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$this->mock = $this->getMock( 'TYPO3\Flow\Cache\Frontend\FrontendInterface' ); |
29
|
|
|
$this->object = new \Aimeos\MW\Cache\Flow( array(), $this->mock ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Tears down the fixture, for example, closes a network connection. |
35
|
|
|
* This method is called after a test is executed. |
36
|
|
|
* |
37
|
|
|
* @access protected |
38
|
|
|
*/ |
39
|
|
|
protected function tearDown() |
40
|
|
|
{ |
41
|
|
|
unset( $this->mock, $this->object ); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
public function testDelete() |
46
|
|
|
{ |
47
|
|
|
$this->mock->expects( $this->once() )->method( 'remove' )->with( $this->equalTo( 'key' ) ); |
48
|
|
|
$this->object->delete( 'key' ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
public function testDeleteWithSiteId() |
53
|
|
|
{ |
54
|
|
|
$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock ); |
55
|
|
|
|
56
|
|
|
$this->mock->expects( $this->once() )->method( 'remove' )->with( $this->equalTo( '1-key' ) ); |
57
|
|
|
$object->delete( 'key' ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
public function testDeleteList() |
62
|
|
|
{ |
63
|
|
|
$this->mock->expects( $this->exactly( 2 ) )->method( 'remove' )->with( $this->equalTo( 'key' ) ); |
64
|
|
|
$this->object->deleteList( array( 'key', 'key' ) ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function testDeleteListWithSiteId() |
69
|
|
|
{ |
70
|
|
|
$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock ); |
71
|
|
|
|
72
|
|
|
$this->mock->expects( $this->once() )->method( 'remove' )->with( $this->equalTo( '1-key' ) ); |
73
|
|
|
$object->deleteList( array( 'key' ) ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
public function testDeleteByTags() |
78
|
|
|
{ |
79
|
|
|
$this->mock->expects( $this->exactly( 2 ) )->method( 'flushByTag' )->with( $this->equalTo( 'tag' ) ); |
80
|
|
|
$this->object->deleteByTags( array( 'tag', 'tag' ) ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
View Code Duplication |
public function testDeleteByTagsWithSiteId() |
|
|
|
|
85
|
|
|
{ |
86
|
|
|
$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock ); |
87
|
|
|
|
88
|
|
|
$this->mock->expects( $this->once() )->method( 'flushByTag' )->with( $this->equalTo( '1-tag' ) ); |
89
|
|
|
$object->deleteByTags( array( 'tag' ) ); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
public function testFlush() |
94
|
|
|
{ |
95
|
|
|
$this->mock->expects( $this->once() )->method( 'flush' ); |
96
|
|
|
$this->object->flush(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
View Code Duplication |
public function testFlushWithSiteId() |
|
|
|
|
101
|
|
|
{ |
102
|
|
|
$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock ); |
103
|
|
|
|
104
|
|
|
$this->mock->expects( $this->once() )->method( 'flushByTag' )->with( $this->equalTo( '1-siteid' ) ); |
105
|
|
|
$object->flush(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
View Code Duplication |
public function testGet() |
|
|
|
|
110
|
|
|
{ |
111
|
|
|
$this->mock->expects( $this->once() )->method( 'get' ) |
112
|
|
|
->with( $this->equalTo( 'key' ) )->will( $this->returnValue( 'value' ) ); |
113
|
|
|
|
114
|
|
|
$this->assertEquals( 'value', $this->object->get( 'key', 'default' ) ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
View Code Duplication |
public function testGetDefault() |
|
|
|
|
119
|
|
|
{ |
120
|
|
|
$this->mock->expects( $this->once() )->method( 'get' ) |
121
|
|
|
->with( $this->equalTo( 'key' ) )->will( $this->returnValue( false ) ); |
122
|
|
|
|
123
|
|
|
$this->assertEquals( 'default', $this->object->get( 'key', 'default' ) ); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
public function testGetWithSiteId() |
128
|
|
|
{ |
129
|
|
|
$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock ); |
130
|
|
|
|
131
|
|
|
$this->mock->expects( $this->once() )->method( 'get' )->with( $this->equalTo( '1-key' ) ); |
132
|
|
|
$object->get( 'key', 'default' ); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
public function testGetList() |
137
|
|
|
{ |
138
|
|
|
$this->mock->expects( $this->exactly( 2 ) )->method( 'get' ) |
139
|
|
|
->will( $this->returnValue( 'value' ) ); |
140
|
|
|
|
141
|
|
|
$expected = array( 'key1' => 'value', 'key2' => 'value' ); |
142
|
|
|
$this->assertEquals( $expected, $this->object->getList( array( 'key1', 'key2' ) ) ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
public function testGetListWithSiteId() |
147
|
|
|
{ |
148
|
|
|
$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock ); |
149
|
|
|
|
150
|
|
|
$this->mock->expects( $this->once() )->method( 'get' )->with( $this->equalTo( '1-key' ) ); |
151
|
|
|
$object->getList( array( 'key' ) ); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
|
155
|
|
View Code Duplication |
public function testGetListByTags() |
|
|
|
|
156
|
|
|
{ |
157
|
|
|
$this->mock->expects( $this->exactly( 2 ) )->method( 'getByTag' ) |
158
|
|
|
->with( $this->equalTo( 'key' ) )->will( $this->returnValue( array( 'key' => 'value' ) ) ); |
159
|
|
|
|
160
|
|
|
$this->assertEquals( array( 'key' => 'value' ), $this->object->getListByTags( array( 'key', 'key' ) ) ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
View Code Duplication |
public function testGetListByTagsWithSiteId() |
|
|
|
|
165
|
|
|
{ |
166
|
|
|
$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock ); |
167
|
|
|
|
168
|
|
|
$this->mock->expects( $this->once() )->method( 'getByTag' ) |
169
|
|
|
->with( $this->equalTo( '1-key' ) )->will( $this->returnValue( array( '1-key' => 'value' ) ) ); |
170
|
|
|
|
171
|
|
|
$this->assertEquals( array( 'key' => 'value' ), $object->getListByTags( array( 'key' ) ) ); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
|
175
|
|
View Code Duplication |
public function testSet() |
|
|
|
|
176
|
|
|
{ |
177
|
|
|
$this->mock->expects( $this->once() )->method( 'set' ) |
178
|
|
|
->with( |
179
|
|
|
$this->equalTo( 'key' ), $this->equalTo( 'value' ), |
180
|
|
|
$this->equalTo( array( 'tag' ) ), $this->greaterThan( 0 ) |
181
|
|
|
); |
182
|
|
|
|
183
|
|
|
$this->object->set( 'key', 'value', array( 'tag' ), '2000-01-01 00:00:00' ); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
|
187
|
|
|
public function testSetWithSiteId() |
188
|
|
|
{ |
189
|
|
|
$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock ); |
190
|
|
|
|
191
|
|
|
$this->mock->expects( $this->once() )->method( 'set' ) |
192
|
|
|
->with( |
193
|
|
|
$this->equalTo( '1-key' ), $this->equalTo( 'value' ), |
194
|
|
|
$this->equalTo( array( '1-siteid', '1-tag' ) ), $this->equalTo( null ) |
195
|
|
|
); |
196
|
|
|
|
197
|
|
|
$object->set( 'key', 'value', array( 'tag' ), null ); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
View Code Duplication |
public function testSetList() |
|
|
|
|
202
|
|
|
{ |
203
|
|
|
$this->mock->expects( $this->once() )->method( 'set' ) |
204
|
|
|
->with( |
205
|
|
|
$this->equalTo( 'key' ), $this->equalTo( 'value' ), |
206
|
|
|
$this->equalTo( array( 'tag' ) ), $this->greaterThan( 0 ) |
207
|
|
|
); |
208
|
|
|
|
209
|
|
|
$expires = array( 'key' => '2000-01-01 00:00:00' ); |
210
|
|
|
$this->object->setList( array( 'key' => 'value' ), array( 'key' => array( 'tag' ) ), $expires ); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
|
214
|
|
View Code Duplication |
public function testSetListWithSiteId() |
|
|
|
|
215
|
|
|
{ |
216
|
|
|
$object = new \Aimeos\MW\Cache\Flow( array( 'siteid' => 1 ), $this->mock ); |
217
|
|
|
|
218
|
|
|
$this->mock->expects( $this->once() )->method( 'set' ) |
219
|
|
|
->with( |
220
|
|
|
$this->equalTo( '1-key' ), $this->equalTo( 'value' ), |
221
|
|
|
$this->equalTo( array( '1-siteid', '1-tag' ) ), $this->equalTo( null ) |
222
|
|
|
); |
223
|
|
|
|
224
|
|
|
$object->setList( array( 'key' => 'value' ), array( 'key' => array( 'tag' ) ), array() ); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
} |
228
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.