Skip to content

Commit 09c1c04

Browse files
[8.x] Add test for FileStore (#40795)
* Add test for FileStore * Add test for Increment in FileStore
1 parent bd9b5e5 commit 09c1c04

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/Cache/CacheFileStoreTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ public function testNullIsReturnedIfFileDoesntExist()
3434
$this->assertNull($value);
3535
}
3636

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+
3752
public function testPutCreatesMissingDirectories()
3853
{
3954
$files = $this->mockFilesystem();
@@ -149,6 +164,19 @@ public function testForeversAreNotRemovedOnIncrement()
149164
$this->assertSame('Hello World', $store->get('foo'));
150165
}
151166

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+
152180
public function testIncrementDoesNotExtendCacheLife()
153181
{
154182
$files = $this->mockFilesystem();

0 commit comments

Comments
 (0)