@@ -67,6 +67,10 @@ protected function tearDown(): void
6767 chmod ($ this ->config ->file ['storePath ' ] . DIRECTORY_SEPARATOR . $ key , 0777 );
6868 unlink ($ this ->config ->file ['storePath ' ] . DIRECTORY_SEPARATOR . $ key );
6969 }
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+ }
7074 }
7175
7276 rmdir ($ this ->config ->file ['storePath ' ]);
@@ -233,6 +237,22 @@ public function testIncrement(): void
233237 $ this ->assertSame (10 , $ this ->handler ->increment (self ::$ key3 , 10 ));
234238 }
235239
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+
236256 public function testDecrement (): void
237257 {
238258 $ this ->handler ->save (self ::$ key1 , 10 );
@@ -246,6 +266,21 @@ public function testDecrement(): void
246266 $ this ->assertSame (-1 , $ this ->handler ->decrement (self ::$ key3 , 1 ));
247267 }
248268
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+
249284 public function testClean (): void
250285 {
251286 $ this ->handler ->save (self ::$ key1 , 1 );
0 commit comments