From 09c1c0431c6cb616560f06e5740eb567364a96ab Mon Sep 17 00:00:00 2001 From: Iman Date: Fri, 4 Feb 2022 05:49:25 +0330 Subject: [PATCH] [8.x] Add test for FileStore (#40795) * Add test for FileStore * Add test for Increment in FileStore --- tests/Cache/CacheFileStoreTest.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/Cache/CacheFileStoreTest.php b/tests/Cache/CacheFileStoreTest.php index e1f50801d6b7..ac32d4642bc9 100755 --- a/tests/Cache/CacheFileStoreTest.php +++ b/tests/Cache/CacheFileStoreTest.php @@ -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(); @@ -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();