Skip to content

Commit

Permalink
Add cache directory if doesnt exist (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
visiover authored and mindplay-dk committed Dec 28, 2016
1 parent 3985ce6 commit a47f559
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion codeception.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ paths:
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: false
colors: true
memory_limit: 1024M
extensions:
enabled:
Expand Down
4 changes: 4 additions & 0 deletions src/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class FileCache implements CacheInterface, CounterInterface
*/
public function __construct($cache_path, $default_ttl)
{
if (! file_exists($cache_path) && file_exists(dirname($cache_path))) {
@mkdir($cache_path, 0777); // ensure that the parent path exists
}

$path = realpath($cache_path);

if ($path === false) {
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/FileCacheCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public function _before()
{
$path = dirname(__DIR__) . "/_output/cache";

@mkdir($path, 0777);
FileSystem::deleteDir($path);

FileSystem::doEmptyDir($path);
$this->cache = new TestableFileCache($path, self::DEFAULT_EXPIRATION);

assert(file_exists($path));

assert(is_writable($path));

$this->cache = new TestableFileCache($path, self::DEFAULT_EXPIRATION);
}

public function _after()
Expand Down Expand Up @@ -62,7 +62,7 @@ public function expirationInSeconds(IntegrationTester $I)
$this->cache->set("key", "value", 10);

$this->cache->skipTime(5);

$I->assertSame("value", $this->cache->get("key"));

$this->cache->skipTime(5);
Expand Down

0 comments on commit a47f559

Please sign in to comment.