Skip to content

Commit

Permalink
Add a test with directory level > 1 (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
particleflux authored Oct 9, 2023
1 parent 398a675 commit 70ee88a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/FileCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,30 @@ public function testDirectoryLevel(): void
$this->assertPathEquals(__DIR__ . '/runtime/cache/a.bin', $cacheFile);
}

/**
* @dataProvider nestedDirectoriesDataProvider
*/
public function testDirectoryLevelWithSubdirs(int $directoryLevel, string $key, string $expectedPath): void
{
$cache = $this->cache->withDirectoryLevel($directoryLevel);

$cache->set($key, 1);

$cacheFile = $this->invokeMethod($cache, 'getCacheFile', [$key]);
$this->assertPathEquals(__DIR__ . "/runtime/cache/$expectedPath.bin", $cacheFile);
}

public function nestedDirectoriesDataProvider(): array
{
return [
'single level' => [1, '0123456789', '01/0123456789'],
'two levels, normal key' => [2, '0123456789', '01/23/0123456789'],
'two levels, short key' => [2, '012', '01/2/012'],
'two levels, too short key' => [2, '0', '0/0'],
'three levels, normal key' => [3, '0123456789', '01/23/45/0123456789'],
];
}

public function testGcProbability(): void
{
$cache = $this->cache->withGcProbability(1_000_000);
Expand Down

0 comments on commit 70ee88a

Please sign in to comment.