/** * @covers Corgi\File\File::touch */ public function testTouch() { $file = new File($this->fullTestFilePath); $this->assertTrue(!FileSystemHelper::doesExist($this->fullTestFilePath)); $this->assertInstanceOf(get_class($file), $file->touch()); $this->assertTrue(FileSystemHelper::doesExist($this->fullTestFilePath)); }
/** * Copies a file/directory to a new parent directory * @param string $newPath * @param bool $overwrite * @return File * @throws CopyException * @throws OverwriteException */ public function copy($newPath, $overwrite = false) { if (!$overwrite && FileSystemHelper::doesExist($newPath)) { throw new OverwriteException($newPath); } $success = copy($this, $newPath); if ($success) { return $this; } else { throw new CopyException($this, $newPath); } }
/** * Renames a file/directory and returns a new file/directory * Also moves the file/directory if necessary * @param string $newPath * @param bool|false $overwrite * @return bool * @throws MoveException * @throws OverwriteException */ public function rename($newPath, $overwrite = false) { if (!$overwrite && FileSystemHelper::doesExist($newPath)) { throw new OverwriteException($newPath); } $success = rename($this->getPath(), $newPath); if ($success) { $this->filePath = FileSystemHelper::toFullPath($newPath); } else { throw new MoveException($this->getPath(), $newPath); } return $success; }
/** * @covers Corgi\File\Helpers\FileSystemHelper::doesExist */ public function testDoesExist() { $this->assertBool(FileSystemHelper::doesExist()); }