public function testMakeInvalids() { $fullPath = sys_get_temp_dir() . Directory::DS . 'PhavourTests'; @mkdir($fullPath); $helper = new Directory(); $makeFake = $helper->createPath(Directory::DS . 'no' . Directory::DS . 'such' . Directory::DS . 'path', 'ok'); $this->assertFalse($makeFake); $makeEmptyPath = $helper->createPath($fullPath, ''); $this->assertFalse($makeEmptyPath); // cover continue for empty paths. $directoryCreate = $helper->createPath($fullPath, 'tests' . Directory::DS . 'directory'); $this->assertTrue($directoryCreate); $helper->recursivelyDeleteFromDirectory($fullPath); }
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)); }
/** * Set a cache value * @param string $key * @param mixed $value * @param integer $ttl (optional) default 86400 * @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 . $md5; $handle = fopen($path, 'w'); if ($handle) { $data = time() + $ttl . PHP_EOL . serialize($value); $success = fwrite($handle, $data); return $success !== false; } // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd }