public function testIsWritable() { $this->root->addChild(vfsStream::newFile('writable.txt', 0222)); $this->root->addChild(vfsStream::newFile('not_writable.txt', 00)); $file1 = new File(vfsStream::url('root/writable.txt')); $this->assertTrue($file1->isWritable()); $file2 = new File(vfsStream::url('root/not_writable.txt')); $this->assertFalse($file2->isWritable()); }
/** * Copy a file to the target location. * @param $new string The new file path * @throws File\Exception\FileNotWritable * @throws File\Exception\DirectoryNotWritable * @throws File\Exception\CopyFailed * @return File The new file object */ public function copy($new) { if (is_dir($new)) { if (!is_writable($new)) { throw new DirectoryNotWritable('The directory "' . $new . '" to which "' . $this->path . '" should be copied is not writable'); } if (substr($new, strlen($new) - 1) !== '/') { $new .= '/'; } $new .= $this->filename; } $file = new File($new); if ($file->exists() && !$file->isWritable()) { throw new FileNotWritable('Target file is not writable: "' . $this->path); } $this->close(); if (!copy($this->path, $new)) { throw new CopyFailed('Could not copy "' . $this->path . '" to "' . $new . '"'); } return $file; }