public function testWriteAttemptWithLock() { $fpath = __DIR__ . '/../../tmp/paratestUsingLock.txt'; $fs = new FileSystem('content written with lock Paratest'); $fs->setFilePath($fpath); $fs->setFileLock(LOCK_EX); $result = $fs->writeAttempt(); $this->assertEquals(FileSystem::OK, $result); }
/** * Write page to cache, and display it. * When write is unsuccessful, string content is returned. * * @param $content string from ob_start * @return string page content */ private function createPage($content) { $storage = new FileSystem($content); try { $storage->setFileLock($this->file_lock); $storage->setFilePath($this->file); } catch (\Exception $e) { $this->log(__METHOD__ . ' FileSystem Exception', $e); } $result = $storage->writeAttempt(); if ($result !== FileSystem::OK) { $this->log(__METHOD__ . ' FileSystem writeAttempt not an OK result: ' . $result); } /** * Return page content */ return $content; }
/** * When directory/file are not writable and writeAttempt is being made. */ public function testWriteAttemptForErrorOpen() { $fpath = $this->getVirtualDirectory() . 'SomeNewFile'; //make base directory not writable chmod($this->getVirtualDirectory(), 0111); $fs = new FileSystem('write attempt'); $fs->setFilePath($fpath); //@supress warning from fopen not being able to open file $this->assertEquals(FileSystem::ERROR_OPEN, @$fs->writeAttempt()); }