Skip to content

Commit

Permalink
fix: allow filesystem cache to be cleared when directory does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
romm committed Jul 10, 2023
1 parent 873961e commit 7824083
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Cache/Compiled/CompiledPhpFileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ public function delete($key): bool

public function clear(): bool
{
if (! is_dir($this->cacheDir)) {
return true;
}

$success = true;

/** @var FilesystemIterator $file */
Expand Down
8 changes: 8 additions & 0 deletions tests/Unit/Cache/Compiled/CompiledPhpFileCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use RuntimeException;

use function iterator_to_array;
use function rmdir;

final class CompiledPhpFileCacheTest extends TestCase
{
Expand Down Expand Up @@ -113,6 +114,13 @@ public function test_clear_cannot_delete_cache_file_returns_false(): void
self::assertFalse($this->cache->clear());
}

public function test_clear_caches_when_cache_directory_does_not_exists_returns_true(): void
{
rmdir($this->files->url());

self::assertTrue($this->cache->clear());
}

public function test_set_multiple_values_sets_values(): void
{
self::assertTrue($this->cache->setMultiple([
Expand Down

0 comments on commit 7824083

Please sign in to comment.