@@ -34,6 +34,21 @@ public function testNullIsReturnedIfFileDoesntExist()
34
34
$ this ->assertNull ($ value );
35
35
}
36
36
37
+ public function testUnserializableFileContentGetDeleted ()
38
+ {
39
+ $ files = $ this ->mockFilesystem ();
40
+ $ hash = sha1 ('foo ' );
41
+ $ cachePath = __DIR__ .'/ ' .substr ($ hash , 0 , 2 ).'/ ' .substr ($ hash , 2 , 2 ).'/ ' .$ hash ;
42
+
43
+ $ files ->expects ($ this ->once ())->method ('get ' )->willReturn ('9999999999-I_am_unserializableee: \(~_~)/ ' );
44
+ $ files ->expects ($ this ->once ())->method ('exists ' )->with ($ this ->equalTo ($ cachePath ))->willReturn (true );
45
+ $ files ->expects ($ this ->once ())->method ('delete ' )->with ($ this ->equalTo ($ cachePath ));
46
+
47
+ $ value = (new FileStore ($ files , __DIR__ ))->get ('foo ' );
48
+
49
+ $ this ->assertNull ($ value );
50
+ }
51
+
37
52
public function testPutCreatesMissingDirectories ()
38
53
{
39
54
$ files = $ this ->mockFilesystem ();
@@ -149,6 +164,19 @@ public function testForeversAreNotRemovedOnIncrement()
149
164
$ this ->assertSame ('Hello World ' , $ store ->get ('foo ' ));
150
165
}
151
166
167
+ public function testIncrementCanAtomicallyJump ()
168
+ {
169
+ $ files = $ this ->mockFilesystem ();
170
+ $ initialValue = '9999999999 ' .serialize (1 );
171
+ $ valueAfterIncrement = '9999999999 ' .serialize (4 );
172
+ $ store = new FileStore ($ files , __DIR__ );
173
+ $ files ->expects ($ this ->once ())->method ('get ' )->willReturn ($ initialValue );
174
+ $ hash = sha1 ('foo ' );
175
+ $ cache_dir = substr ($ hash , 0 , 2 ).'/ ' .substr ($ hash , 2 , 2 );
176
+ $ files ->expects ($ this ->once ())->method ('put ' )->with ($ this ->equalTo (__DIR__ .'/ ' .$ cache_dir .'/ ' .$ hash ), $ this ->equalTo ($ valueAfterIncrement ));
177
+ $ store ->increment ('foo ' , 3 );
178
+ }
179
+
152
180
public function testIncrementDoesNotExtendCacheLife ()
153
181
{
154
182
$ files = $ this ->mockFilesystem ();
0 commit comments