afterEach(function () {
Dir::remove($this->temp);
});
it("clears the cache", function () {
$this->interceptor->clearCache();
expect(file_exists($this->customCachePath))->toBe(false);
});
it("bails out if the cache has already been cleared", function () {
$this->interceptor->clearCache();
$this->interceptor->clearCache();
expect(file_exists($this->customCachePath))->toBe(false);
});
});
describe("->watch()/unwatch()", function () {
it("add some file to be watched", function () {
$this->temp = Dir::tempnam(null, 'cache');
touch($this->temp . DS . 'watched1.php');
touch($this->temp . DS . 'watched2.php');
$watched = [$this->temp . DS . 'watched1.php', $this->temp . DS . 'watched2.php'];
$this->interceptor = Interceptor::patch(['cachePath' => $this->cachePath]);
$this->interceptor->watch($this->temp . DS . 'watched1.php');
expect($this->interceptor->watched())->toBe([$watched[0]]);
$this->interceptor->watch($this->temp . DS . 'watched2.php');
expect($this->interceptor->watched())->toBe($watched);
$this->interceptor->unwatch($this->temp . DS . 'watched1.php');
expect($this->interceptor->watched())->toBe([$watched[1]]);
$this->interceptor->unwatch($this->temp . DS . 'watched2.php');
expect($this->interceptor->watched())->toBe([]);
Dir::remove($this->temp);
});
});