Beispiel #1
0
 public function testDelete()
 {
     $fileToDelete = vfsStream::newFile('deletable.txt', 0444);
     $this->root->addChild($fileToDelete);
     $file = new File($fileToDelete->url());
     $file->delete();
     $this->assertFalse(file_exists($fileToDelete->url()));
     $this->assertFalse($file->exists());
 }
Beispiel #2
0
 /**
  * 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;
 }