Skip to content

Commit 271a3ed

Browse files
committed
bug fix for issue #232
1 parent e3bafec commit 271a3ed

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Cache.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use DateInterval;
1919
use FilesystemIterator;
2020
use Generator;
21+
use InvalidArgumentException;
2122
use Psr\SimpleCache\CacheInterface;
2223
use Traversable;
2324
use function chmod;
@@ -88,6 +89,10 @@ public function __construct(string $cache_path = '')
8889
$this->mkdir($cache_path); // ensure that the parent path exists
8990
}
9091

92+
if (! is_writable($cache_path.DIRECTORY_SEPARATOR)) {
93+
throw new InvalidArgumentException(sprintf('cache path does not exist or is not writable: %s', $cache_path));
94+
}
95+
9196
$this->cache_path = $cache_path;
9297
}
9398

tests/CacheTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,14 @@ public function testConstructorOnParentCachePathIsNotExisted()
6969

7070
public function testSetOnNotWritableCachePath()
7171
{
72+
self::expectException(\InvalidArgumentException::class);
7273
$cache = new Cache('/bin');
73-
self::assertFalse($cache->set('key', 'value'));
74+
}
75+
76+
public function testSetOnNotExistingCachePath()
77+
{
78+
self::expectException(\InvalidArgumentException::class);
79+
$cache = new Cache('/foo/bar');
7480
}
7581

7682
/**

0 commit comments

Comments
 (0)