Example #1
0
 public function testRecusiveDelete()
 {
     $fullPath = sys_get_temp_dir() . Directory::DS . 'PhavourTests';
     mkdir($fullPath);
     touch($fullPath . Directory::DS . '1');
     $this->assertFileExists($fullPath . Directory::DS . '1');
     @mkdir($fullPath . Directory::DS . 'dir');
     touch($fullPath . Directory::DS . 'dir' . Directory::DS . '2');
     $this->assertFileExists($fullPath . Directory::DS . 'dir' . Directory::DS . '2');
     @mkdir($fullPath . Directory::DS . 'dir');
     $dir = new Directory();
     $dir->recursivelyDeleteFromDirectory($fullPath . Directory::DS . '1');
     $dir->recursivelyDeleteFromDirectory($fullPath);
     $this->assertFileNotExists($fullPath . Directory::DS . '1');
     $this->assertFileNotExists($fullPath . Directory::DS . 'dir' . Directory::DS . '2');
 }
 public function testGetInvalid()
 {
     $name = rand(0, 999);
     $md5 = md5($name);
     $file = $this->path . Directory::DS . substr($md5, 0, 2) . Directory::DS . substr($md5, 2, 2) . Directory::DS . 'PCAFS_' . $md5;
     $this->dir->createPath($this->path, substr($md5, 0, 2) . Directory::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 . Directory::DS . substr($md5, 0, 2) . Directory::DS . substr($md5, 2, 2) . Directory::DS . 'PCAFS_' . $md5;
     $this->dir->createPath($this->path, substr($md5, 0, 2) . Directory::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 . Directory::DS . substr($md5, 0, 2) . Directory::DS . substr($md5, 2, 2) . Directory::DS . 'PCAFS_' . $md5;
     $this->dir->createPath($this->path, substr($md5, 0, 2) . Directory::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 . Directory::DS . substr($md5, 0, 2) . Directory::DS . substr($md5, 2, 2) . Directory::DS . 'PCAFS_' . $md5;
     $this->dir->createPath($this->path, substr($md5, 0, 2) . Directory::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 . Directory::DS . substr($md5, 0, 2) . Directory::DS . substr($md5, 2, 2) . Directory::DS . 'PCAFS_' . $md5;
     $this->dir->createPath($this->path, substr($md5, 0, 2) . Directory::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 . Directory::DS . substr($md5, 0, 2) . Directory::DS . substr($md5, 2, 2) . Directory::DS . 'PCAFS_' . $md5;
     $this->dir->createPath($this->path, substr($md5, 0, 2) . Directory::DS . substr($md5, 2, 2));
     $handle = fopen($file, 'w');
     fwrite($handle, 0);
     fclose($handle);
     $adapter = clone $this->adapter;
     $this->assertFalse($adapter->get($name));
 }
Example #3
0
 /**
  * Flush all existing Cache.
  * @return boolean
  */
 public function flush()
 {
     try {
         $this->helper->recursivelyDeleteFromDirectory($this->path);
         return true;
         // @codeCoverageIgnoreStart
     } catch (\Exception $e) {
     }
     return false;
     // @codeCoverageIgnoreEnd
 }