Skip to content

Commit

Permalink
[8.x] Add test for FileStore (#40795)
Browse files Browse the repository at this point in the history
* Add test for FileStore

* Add test for Increment in FileStore
  • Loading branch information
imanghafoori1 authored Feb 4, 2022
1 parent bd9b5e5 commit 09c1c04
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/Cache/CacheFileStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ public function testNullIsReturnedIfFileDoesntExist()
$this->assertNull($value);
}

public function testUnserializableFileContentGetDeleted()
{
$files = $this->mockFilesystem();
$hash = sha1('foo');
$cachePath = __DIR__.'/'.substr($hash, 0, 2).'/'.substr($hash, 2, 2).'/'.$hash;

$files->expects($this->once())->method('get')->willReturn('9999999999-I_am_unserializableee: \(~_~)/');
$files->expects($this->once())->method('exists')->with($this->equalTo($cachePath))->willReturn(true);
$files->expects($this->once())->method('delete')->with($this->equalTo($cachePath));

$value = (new FileStore($files, __DIR__))->get('foo');

$this->assertNull($value);
}

public function testPutCreatesMissingDirectories()
{
$files = $this->mockFilesystem();
Expand Down Expand Up @@ -149,6 +164,19 @@ public function testForeversAreNotRemovedOnIncrement()
$this->assertSame('Hello World', $store->get('foo'));
}

public function testIncrementCanAtomicallyJump()
{
$files = $this->mockFilesystem();
$initialValue = '9999999999'.serialize(1);
$valueAfterIncrement = '9999999999'.serialize(4);
$store = new FileStore($files, __DIR__);
$files->expects($this->once())->method('get')->willReturn($initialValue);
$hash = sha1('foo');
$cache_dir = substr($hash, 0, 2).'/'.substr($hash, 2, 2);
$files->expects($this->once())->method('put')->with($this->equalTo(__DIR__.'/'.$cache_dir.'/'.$hash), $this->equalTo($valueAfterIncrement));
$store->increment('foo', 3);
}

public function testIncrementDoesNotExtendCacheLife()
{
$files = $this->mockFilesystem();
Expand Down

0 comments on commit 09c1c04

Please sign in to comment.