public function testRecusiveDelete() { $fullPath = sys_get_temp_dir() . FileSystemHelper::DS . 'OhCacheTests'; mkdir($fullPath); touch($fullPath . FileSystemHelper::DS . '1'); $this->assertFileExists($fullPath . FileSystemHelper::DS . '1'); @mkdir($fullPath . FileSystemHelper::DS . 'dir'); touch($fullPath . FileSystemHelper::DS . 'dir' . FileSystemHelper::DS . '2'); $this->assertFileExists($fullPath . FileSystemHelper::DS . 'dir' . FileSystemHelper::DS . '2'); @mkdir($fullPath . FileSystemHelper::DS . 'dir'); $dir = new FileSystemHelper(); $dir->recursivelyDeleteFromDirectory($fullPath . FileSystemHelper::DS . '1'); $dir->recursivelyDeleteFromDirectory($fullPath); $this->assertFileNotExists($fullPath . FileSystemHelper::DS . '1'); $this->assertFileNotExists($fullPath . FileSystemHelper::DS . 'dir' . FileSystemHelper::DS . '2'); }
/** * Flush the entire cache. * * @return boolean */ public function flush() { try { $this->helper->recursivelyDeleteFromDirectory($this->path, true); return true; // @codeCoverageIgnoreStart } catch (\Exception $e) { } return false; // @codeCoverageIgnoreEnd }
public function testGetInvalid() { $name = rand(0, 999); $md5 = md5($name); $file = $this->path . FileSystemHelper::DS; $file .= substr($md5, 0, 2) . FileSystemHelper::DS; $file .= substr($md5, 2, 2) . FileSystemHelper::DS; $file .= 'OHAFS_' . $md5; $this->dir->createPath($this->path, substr($md5, 0, 2) . FileSystemHelper::DS . substr($md5, 2, 2)); $handle = fopen($file, 'w'); fwrite($handle, time() + 100 . PHP_EOL . 'a;x/sdr'); fclose($handle); chmod($file, 701); $adapter = clone $this->adapter; $this->assertFalse($adapter->get($name)); $name = rand(0, 999); $md5 = md5($name); $file = $this->path . FileSystemHelper::DS; $file .= substr($md5, 0, 2) . FileSystemHelper::DS; $file .= substr($md5, 2, 2) . FileSystemHelper::DS; $file .= 'OHAFS_' . $md5; $this->dir->createPath($this->path, substr($md5, 0, 2) . FileSystemHelper::DS . substr($md5, 2, 2)); $handle = fopen($file, 'w'); fwrite($handle, time() + 100 . PHP_EOL . 'a;x/sdr'); fclose($handle); $adapter = clone $this->adapter; $this->assertFalse($adapter->get($name)); $name = rand(0, 999); $md5 = md5($name); $file = $this->path . FileSystemHelper::DS; $file .= substr($md5, 0, 2) . FileSystemHelper::DS; $file .= substr($md5, 2, 2) . FileSystemHelper::DS; $file .= 'OHAFS_' . $md5; $this->dir->createPath($this->path, substr($md5, 0, 2) . FileSystemHelper::DS . substr($md5, 2, 2)); $handle = fopen($file, 'w'); fwrite($handle, 'abc'); fclose($handle); $adapter = clone $this->adapter; $this->assertFalse($adapter->get($name)); $name = rand(0, 999); $md5 = md5($name); $file = $this->path . FileSystemHelper::DS; $file .= substr($md5, 0, 2) . FileSystemHelper::DS; $file .= substr($md5, 2, 2) . FileSystemHelper::DS; $file .= 'OHAFS_' . $md5; $this->dir->createPath($this->path, substr($md5, 0, 2) . FileSystemHelper::DS . substr($md5, 2, 2)); $handle = fopen($file, 'w'); fwrite($handle, 'abc'); fclose($handle); $adapter = clone $this->adapter; $this->assertFalse($adapter->renew($name, 100)); $name = rand(0, 999); $md5 = md5($name); $file = $this->path . FileSystemHelper::DS; $file .= substr($md5, 0, 2) . FileSystemHelper::DS; $file .= substr($md5, 2, 2) . FileSystemHelper::DS; $file .= 'OHAFS_' . $md5; $this->dir->createPath($this->path, substr($md5, 0, 2) . FileSystemHelper::DS . substr($md5, 2, 2)); $handle = fopen($file, 'w'); fwrite($handle, time() + 100 . PHP_EOL . 'abc'); fclose($handle); $adapter = clone $this->adapter; $this->assertFalse($adapter->renew($name, 100)); $name = rand(0, 999); $md5 = md5($name); $file = $this->path . FileSystemHelper::DS; $file .= substr($md5, 0, 2) . FileSystemHelper::DS; $file .= substr($md5, 2, 2) . FileSystemHelper::DS; $file .= 'OHAFS_' . $md5; $this->dir->createPath($this->path, substr($md5, 0, 2) . FileSystemHelper::DS . substr($md5, 2, 2)); $handle = fopen($file, 'w'); fwrite($handle, 0); fclose($handle); $adapter = clone $this->adapter; $this->assertFalse($adapter->get($name)); }