16
16
namespace Pdp \Tests ;
17
17
18
18
use DateInterval ;
19
+ use Generator ;
19
20
use Iterator ;
20
21
use org \bovigo \vfs \vfsStream ;
21
22
use Pdp \Cache ;
34
35
*/
35
36
class CacheTest extends TestCase
36
37
{
38
+ /**
39
+ * @var Cache
40
+ */
37
41
protected $ cache ;
38
42
43
+ /**
44
+ * @var \org\bovigo\vfs\vfsStreamDirectory
45
+ */
39
46
protected $ root ;
40
47
48
+ /**
49
+ * @var string
50
+ */
41
51
protected $ cacheDir ;
42
52
43
- public function setUp ()
53
+ public function setUp (): void
44
54
{
45
55
$ this ->root = vfsStream::setup ('pdp ' );
46
56
vfsStream::create (['cache ' => []], $ this ->root );
47
57
$ this ->cacheDir = vfsStream::url ('pdp/cache ' );
48
58
$ this ->cache = new Cache ($ this ->cacheDir );
49
59
}
50
60
51
- public function tearDown ()
61
+ public function tearDown (): void
52
62
{
53
- $ this ->cache = null ;
54
- $ this ->cacheDir = null ;
55
- $ this ->root = null ;
63
+ unset($ this ->cache , $ this ->cacheDir , $ this ->root );
56
64
}
57
65
58
- public function testConstructorOnEmptyCachePath ()
66
+ public function testConstructorOnEmptyCachePath (): void
59
67
{
60
68
$ cache = new Cache ('' );
61
69
self ::assertNull ($ cache ->get ('invalid_key ' ));
62
70
}
63
71
64
- public function testConstructorOnParentCachePathIsNotExisted ()
72
+ public function testConstructorOnParentCachePathIsNotExisted (): void
65
73
{
66
74
$ cache = new Cache (vfsStream::url ('pdp/cache_not_exist ' ));
67
75
self ::assertNull ($ cache ->get ('invalid_key ' ));
68
76
}
69
77
70
- public function testSetOnNotWritableCachePath ()
78
+ public function testSetOnNotWritableCachePath (): void
71
79
{
72
80
self ::expectException (\InvalidArgumentException::class);
73
81
$ cache = new Cache ('/bin ' );
74
82
}
75
83
76
- public function testSetOnNotExistingCachePath ()
84
+ public function testSetOnNotExistingCachePath (): void
77
85
{
78
86
self ::expectException (\InvalidArgumentException::class);
79
87
$ cache = new Cache ('/foo/bar ' );
@@ -84,13 +92,13 @@ public function testSetOnNotExistingCachePath()
84
92
*
85
93
* @param mixed $expected
86
94
*/
87
- public function testSetGet ($ expected )
95
+ public function testSetGet ($ expected ): void
88
96
{
89
97
$ this ->cache ->set ('foo ' , $ expected );
90
98
self ::assertEquals ($ expected , $ this ->cache ->get ('foo ' ));
91
99
}
92
100
93
- public function storableValuesProvider ()
101
+ public function storableValuesProvider (): iterable
94
102
{
95
103
return [
96
104
'string ' => ['bar ' ],
@@ -105,27 +113,27 @@ public function storableValuesProvider()
105
113
/**
106
114
* @depends testSetGet
107
115
*/
108
- public function testDelete ()
116
+ public function testDelete (): void
109
117
{
110
118
$ this ->cache ->set ('foo ' , 'bar ' );
111
119
self ::assertEquals ('bar ' , $ this ->cache ->get ('foo ' ));
112
120
$ this ->cache ->delete ('foo ' );
113
121
self ::assertNull ($ this ->cache ->get ('foo ' ));
114
122
}
115
123
116
- public function testGetInvalidArg ()
124
+ public function testGetInvalidArg (): void
117
125
{
118
126
self ::expectException (InvalidArgumentException::class);
119
127
$ this ->cache ->get (null );
120
128
}
121
129
122
- public function testInvalidKey ()
130
+ public function testInvalidKey (): void
123
131
{
124
132
self ::expectException (InvalidArgumentException::class);
125
133
$ this ->cache ->get ('foo:bar ' , 'bar ' );
126
134
}
127
135
128
- public function testSetInvalidTTL ()
136
+ public function testSetInvalidTTL (): void
129
137
{
130
138
self ::expectException (InvalidArgumentException::class);
131
139
$ this ->cache ->set ('foo ' , 'bar ' , date_create ());
@@ -134,15 +142,15 @@ public function testSetInvalidTTL()
134
142
/**
135
143
* @depends testDelete
136
144
*/
137
- public function testGetNotFound ()
145
+ public function testGetNotFound (): void
138
146
{
139
147
self ::assertNull ($ this ->cache ->get ('notfound ' ));
140
148
}
141
149
142
150
/**
143
151
* @depends testDelete
144
152
*/
145
- public function testGetNotFoundDefault ()
153
+ public function testGetNotFoundDefault (): void
146
154
{
147
155
$ expected = 'chickpeas ' ;
148
156
self ::assertEquals ($ expected , $ this ->cache ->get ('notfound ' , $ expected ));
@@ -152,7 +160,7 @@ public function testGetNotFoundDefault()
152
160
* @depends testSetGet
153
161
* @slow
154
162
*/
155
- public function testSetExpire ()
163
+ public function testSetExpire (): void
156
164
{
157
165
$ this ->cache ->set ('foo ' , 'bar ' , 1 );
158
166
self ::assertEquals ('bar ' , $ this ->cache ->get ('foo ' ));
@@ -166,7 +174,7 @@ public function testSetExpire()
166
174
* @depends testSetGet
167
175
* @slow
168
176
*/
169
- public function testSetExpireDateInterval ()
177
+ public function testSetExpireDateInterval (): void
170
178
{
171
179
$ this ->cache ->set ('foo ' , 'bar ' , new DateInterval ('PT1S ' ));
172
180
self ::assertEquals ('bar ' , $ this ->cache ->get ('foo ' ));
@@ -176,13 +184,13 @@ public function testSetExpireDateInterval()
176
184
self ::assertNull ($ this ->cache ->get ('foo ' ));
177
185
}
178
186
179
- public function testSetInvalidArg ()
187
+ public function testSetInvalidArg (): void
180
188
{
181
189
self ::expectException (InvalidArgumentException::class);
182
190
$ this ->cache ->set (null , 'bar ' );
183
191
}
184
192
185
- public function testDeleteInvalidArg ()
193
+ public function testDeleteInvalidArg (): void
186
194
{
187
195
self ::expectException (InvalidArgumentException::class);
188
196
$ this ->cache ->delete (null );
@@ -191,7 +199,7 @@ public function testDeleteInvalidArg()
191
199
/**
192
200
* @depends testSetGet
193
201
*/
194
- public function testClearCache ()
202
+ public function testClearCache (): void
195
203
{
196
204
$ this ->cache ->set ('foo ' , 'bar ' );
197
205
$ this ->cache ->clear ();
@@ -201,7 +209,7 @@ public function testClearCache()
201
209
/**
202
210
* @depends testSetGet
203
211
*/
204
- public function testHas ()
212
+ public function testHas (): void
205
213
{
206
214
$ this ->cache ->set ('foo ' , 'bar ' );
207
215
self ::assertTrue ($ this ->cache ->has ('foo ' ));
@@ -210,12 +218,12 @@ public function testHas()
210
218
/**
211
219
* @depends testHas
212
220
*/
213
- public function testHasNot ()
221
+ public function testHasNot (): void
214
222
{
215
223
self ::assertFalse ($ this ->cache ->has ('not-found ' ));
216
224
}
217
225
218
- public function testHasInvalidArg ()
226
+ public function testHasInvalidArg (): void
219
227
{
220
228
self ::expectException (InvalidArgumentException::class);
221
229
$ this ->cache ->has (null );
@@ -224,7 +232,7 @@ public function testHasInvalidArg()
224
232
/**
225
233
* @depends testSetGet
226
234
*/
227
- public function testSetGetMultiple ()
235
+ public function testSetGetMultiple (): void
228
236
{
229
237
$ values = [
230
238
'key1 ' => 'value1 ' ,
@@ -247,15 +255,15 @@ public function testSetGetMultiple()
247
255
/**
248
256
* @depends testSetGet
249
257
*/
250
- public function testSetGetMultipleGenerator ()
258
+ public function testSetGetMultipleGenerator (): void
251
259
{
252
260
$ values = [
253
261
'key1 ' => 'value1 ' ,
254
262
'key2 ' => 'value2 ' ,
255
263
'key3 ' => 'value3 ' ,
256
264
];
257
265
258
- $ gen = function () use ($ values ) {
266
+ $ gen = function () use ($ values ): Generator {
259
267
foreach ($ values as $ key => $ value ) {
260
268
yield $ key => $ value ;
261
269
}
@@ -277,15 +285,15 @@ public function testSetGetMultipleGenerator()
277
285
/**
278
286
* @depends testSetGet
279
287
*/
280
- public function testSetGetMultipleGenerator2 ()
288
+ public function testSetGetMultipleGenerator2 (): void
281
289
{
282
290
$ values = [
283
291
'key1 ' => 'value1 ' ,
284
292
'key2 ' => 'value2 ' ,
285
293
'key3 ' => 'value3 ' ,
286
294
];
287
295
288
- $ gen = function () use ($ values ) {
296
+ $ gen = function () use ($ values ): Generator {
289
297
foreach ($ values as $ key => $ value ) {
290
298
yield $ key ;
291
299
}
@@ -308,7 +316,7 @@ public function testSetGetMultipleGenerator2()
308
316
* @depends testSetExpire
309
317
* @slow
310
318
*/
311
- public function testSetMultipleExpireDateIntervalNotExpired ()
319
+ public function testSetMultipleExpireDateIntervalNotExpired (): void
312
320
{
313
321
$ values = [
314
322
'key1 ' => 'value1 ' ,
@@ -333,7 +341,7 @@ public function testSetMultipleExpireDateIntervalNotExpired()
333
341
/**
334
342
* @slow
335
343
*/
336
- public function testSetMultipleExpireDateIntervalExpired ()
344
+ public function testSetMultipleExpireDateIntervalExpired (): void
337
345
{
338
346
$ values = [
339
347
'key1 ' => 'value1 ' ,
@@ -370,7 +378,7 @@ public function testSetMultipleExpireDateIntervalExpired()
370
378
/**
371
379
* @slow
372
380
*/
373
- public function testSetMultipleExpireDateIntervalInt ()
381
+ public function testSetMultipleExpireDateIntervalInt (): void
374
382
{
375
383
$ values = [
376
384
'key1 ' => 'value1 ' ,
@@ -404,13 +412,13 @@ public function testSetMultipleExpireDateIntervalInt()
404
412
self ::assertEquals ([], $ expected );
405
413
}
406
414
407
- public function testSetMultipleInvalidArg ()
415
+ public function testSetMultipleInvalidArg (): void
408
416
{
409
417
self ::expectException (InvalidArgumentException::class);
410
418
$ this ->cache ->setMultiple (null );
411
419
}
412
420
413
- public function testGetMultipleInvalidArg ()
421
+ public function testGetMultipleInvalidArg (): void
414
422
{
415
423
self ::expectException (InvalidArgumentException::class);
416
424
$ result = $ this ->cache ->getMultiple (null );
@@ -426,7 +434,7 @@ public function testGetMultipleInvalidArg()
426
434
/**
427
435
* @depends testSetGetMultiple
428
436
*/
429
- public function testDeleteMultipleDefaultGet ()
437
+ public function testDeleteMultipleDefaultGet (): void
430
438
{
431
439
$ values = [
432
440
'key1 ' => 'value1 ' ,
@@ -459,7 +467,7 @@ public function testDeleteMultipleDefaultGet()
459
467
/**
460
468
* @depends testSetGetMultiple
461
469
*/
462
- public function testDeleteMultipleGenerator ()
470
+ public function testDeleteMultipleGenerator (): void
463
471
{
464
472
$ values = [
465
473
'key1 ' => 'value1 ' ,
@@ -469,7 +477,7 @@ public function testDeleteMultipleGenerator()
469
477
470
478
$ this ->cache ->setMultiple ($ values );
471
479
472
- $ gen = function () {
480
+ $ gen = function (): Generator {
473
481
yield 'key1 ' ;
474
482
yield 'key3 ' ;
475
483
};
@@ -494,7 +502,7 @@ public function testDeleteMultipleGenerator()
494
502
self ::assertEquals ([], $ expected );
495
503
}
496
504
497
- public function testDeleteMultipleInvalidArg ()
505
+ public function testDeleteMultipleInvalidArg (): void
498
506
{
499
507
self ::expectException (InvalidArgumentException::class);
500
508
$ this ->cache ->deleteMultiple (null );
0 commit comments