public function testMakeInvalids()
 {
     $fullPath = sys_get_temp_dir() . FileSystemHelper::DS . 'OhCacheTests';
     @mkdir($fullPath);
     $helper = new FileSystemHelper();
     $makeFake = $helper->createPath(FileSystemHelper::DS . 'no' . FileSystemHelper::DS . 'such' . FileSystemHelper::DS . 'path', 'ok');
     $this->assertFalse($makeFake);
     $makeEmptyPath = $helper->createPath($fullPath, '');
     $this->assertFalse($makeEmptyPath);
     // cover continue for empty paths.
     $directoryCreate = $helper->createPath($fullPath, 'tests' . FileSystemHelper::DS . 'directory');
     $this->assertTrue($directoryCreate);
     $helper->recursivelyDeleteFromDirectory($fullPath);
 }
Exemplo n.º 2
0
 /**
  * Set a value in cache by key name, specifying the TTL
  *
  * @param string $key
  * @param mixed $value
  * @param integer $ttl
  * @return boolean
  */
 public function set($key, $value, $ttl = self::DEFAULT_TTL)
 {
     $md5 = md5($key);
     $folderPath = $this->getFolderPathFromMd5($md5);
     $create = $this->helper->createPath($this->path, $folderPath);
     if (!$create) {
         return false;
     }
     $basePaths = $this->path . self::DS . $folderPath;
     $path = $basePaths . self::DS . $this->prefix . $this->getKeyString($md5);
     $handle = fopen($path, 'w');
     if ($handle) {
         $data = time() + $ttl . PHP_EOL . serialize($value);
         $success = fwrite($handle, $data);
         @fclose($handle);
         return $success !== false;
     }
     // @codeCoverageIgnoreStart
     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));
 }