Skip to content

Commit c7f4c23

Browse files
Add tests for put method of FileStore (#40811)
1 parent 1c15d08 commit c7f4c23

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

tests/Cache/CacheFileStoreTest.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,43 @@ public function testPutCreatesMissingDirectories()
6262
$this->assertTrue($result);
6363
}
6464

65-
public function testExpiredItemsReturnNull()
65+
public function testPutWillConsiderZeroAsEternalTime()
66+
{
67+
$files = $this->mockFilesystem();
68+
69+
$hash = sha1('O--L / key');
70+
$filePath = __DIR__.'/'.substr($hash, 0, 2).'/'.substr($hash, 2, 2).'/'.$hash;
71+
$ten9s = '9999999999'; // The "forever" time value.
72+
$fileContents = $ten9s.serialize('gold');
73+
$exclusiveLock = true;
74+
75+
$files->expects($this->once())->method('put')->with(
76+
$this->equalTo($filePath),
77+
$this->equalTo($fileContents),
78+
$this->equalTo($exclusiveLock) // Ensure we do lock the file while putting.
79+
)->willReturn(strlen($fileContents));
80+
81+
(new FileStore($files, __DIR__))->put('O--L / key', 'gold', 0);
82+
}
83+
84+
public function testPutWillConsiderBigValuesAsEternalTime()
85+
{
86+
$files = $this->mockFilesystem();
87+
88+
$hash = sha1('O--L / key');
89+
$filePath = __DIR__.'/'.substr($hash, 0, 2).'/'.substr($hash, 2, 2).'/'.$hash;
90+
$ten9s = '9999999999'; // The "forever" time value.
91+
$fileContents = $ten9s.serialize('gold');
92+
93+
$files->expects($this->once())->method('put')->with(
94+
$this->equalTo($filePath),
95+
$this->equalTo($fileContents),
96+
);
97+
98+
(new FileStore($files, __DIR__))->put('O--L / key', 'gold', (int) $ten9s + 1);
99+
}
100+
101+
public function testExpiredItemsReturnNullAndGetDeleted()
66102
{
67103
$files = $this->mockFilesystem();
68104
$contents = '0000000000';

0 commit comments

Comments
 (0)