@@ -67,6 +67,10 @@ protected function tearDown(): void
67
67
chmod ($ this ->config ->file ['storePath ' ] . DIRECTORY_SEPARATOR . $ key , 0777 );
68
68
unlink ($ this ->config ->file ['storePath ' ] . DIRECTORY_SEPARATOR . $ key );
69
69
}
70
+ if (is_file ($ this ->config ->file ['storePath ' ] . DIRECTORY_SEPARATOR . $ this ->config ->prefix . $ key )) {
71
+ chmod ($ this ->config ->file ['storePath ' ] . DIRECTORY_SEPARATOR . $ this ->config ->prefix . $ key , 0777 );
72
+ unlink ($ this ->config ->file ['storePath ' ] . DIRECTORY_SEPARATOR . $ this ->config ->prefix . $ key );
73
+ }
70
74
}
71
75
72
76
rmdir ($ this ->config ->file ['storePath ' ]);
@@ -233,6 +237,22 @@ public function testIncrement(): void
233
237
$ this ->assertSame (10 , $ this ->handler ->increment (self ::$ key3 , 10 ));
234
238
}
235
239
240
+ public function testIncrementWithDefaultPrefix (): void
241
+ {
242
+ $ this ->config ->prefix = 'test_ ' ;
243
+ $ this ->handler = new FileHandler ($ this ->config );
244
+ $ this ->handler ->initialize ();
245
+
246
+ $ this ->handler ->save (self ::$ key1 , 1 );
247
+ $ this ->handler ->save (self ::$ key2 , 'value ' );
248
+
249
+ $ this ->assertSame (11 , $ this ->handler ->increment (self ::$ key1 , 10 ));
250
+ $ this ->assertSame ($ this ->handler ->increment (self ::$ key1 , 10 ), $ this ->handler ->get (self ::$ key1 ));
251
+ $ this ->assertFalse ($ this ->handler ->increment (self ::$ key2 , 10 ));
252
+ $ this ->assertSame (10 , $ this ->handler ->increment (self ::$ key3 , 10 ));
253
+ $ this ->assertSame ($ this ->handler ->increment (self ::$ key3 , 10 ), $ this ->handler ->get (self ::$ key3 ));
254
+ }
255
+
236
256
public function testDecrement (): void
237
257
{
238
258
$ this ->handler ->save (self ::$ key1 , 10 );
@@ -246,6 +266,21 @@ public function testDecrement(): void
246
266
$ this ->assertSame (-1 , $ this ->handler ->decrement (self ::$ key3 , 1 ));
247
267
}
248
268
269
+ public function testDecrementWithDefaultPrefix (): void
270
+ {
271
+ $ this ->handler ->save (self ::$ key1 , 10 );
272
+ $ this ->handler ->save (self ::$ key2 , 'value ' );
273
+
274
+ // Line following commented out to force the cache to add a zero entry for key3
275
+ // $this->fileHandler->save(self::$key3, 0);
276
+
277
+ $ this ->assertSame (9 , $ this ->handler ->decrement (self ::$ key1 , 1 ));
278
+ $ this ->assertSame ($ this ->handler ->decrement (self ::$ key1 , 1 ), $ this ->handler ->get (self ::$ key1 ));
279
+ $ this ->assertFalse ($ this ->handler ->decrement (self ::$ key2 , 1 ));
280
+ $ this ->assertSame (-1 , $ this ->handler ->decrement (self ::$ key3 , 1 ));
281
+ $ this ->assertSame ($ this ->handler ->decrement (self ::$ key3 , 1 ), $ this ->handler ->get (self ::$ key3 ));
282
+ }
283
+
249
284
public function testClean (): void
250
285
{
251
286
$ this ->handler ->save (self ::$ key1 , 1 );
0 commit comments