/** * @dataProvider providerGetParent */ public function testGetParent($expected, $value) { $currentFileSystem = FileSystem::getInstance(); $windowsFileSystem = new WindowsFileSystem(); Reflection::setProperty(FileSystem::getInstance(), 'instance', $windowsFileSystem); $file = new File($value); $this->assertEquals(new File($expected), $windowsFileSystem->getParent($file)); Reflection::setProperty(FileSystem::getInstance(), 'instance', $currentFileSystem); }
/** * Construct a file object * @param string|File $path * @param string|File $child file in the provided path (optional) * @return null * @throws zibo\library\filesystem\exception\FileSystemException when the * path is empty * @throws zibo\library\filesystem\exception\FileSystemException when the * child is absolute */ public function __construct($path, $child = null) { $this->fs = FileSystem::getInstance(); $this->isRootPath = false; $this->path = self::retrievePath($this->fs, $path, $this->isRootPath); if ($child != null) { $child = new File($child); if ($child->isAbsolute()) { throw new FileSystemException('Child ' . $child->getPath() . ' cannot be absolute'); } $childPath = $child->getPath(); if ($child->hasPharProtocol()) { $childPath = substr($childPath, 7); } if (!$this->isRootPath) { $this->path .= self::DIRECTORY_SEPARATOR; } $this->path .= $childPath; } if ($this->isInPhar() && !$this->hasPharProtocol()) { $this->path = 'phar://' . $this->path; } }
/** * Move this file * @param File $destination * @return null * @throws zibo\library\filesystem\exception\FileSystemException when the file could not be moved */ public function move(File $destination) { $fs = FileSystem::getInstance(); $fs->move($this, $destination); }
/** * @expectedException zibo\library\filesystem\exception\FileSystemException */ public function testMoveWithUnexistingFileThrowsException() { $fs = FileSystem::getInstance(); $source = new File('unexistant'); $destination = new File('unexistant.move'); $fs->move($source, $destination); }