/** * @covers Corgi\File\Base\FileSystemNode::__toString */ public function testToString() { $file = new File($this->fullTestFilePath); $this->assertEquals('string', gettype($file->__toString())); $directory = new Directory($this->fullTestFilePath); $this->assertEquals('string', gettype($directory->__toString())); }
/** * Permanently deletes a directory (recursive) * @param bool|false $failSilently * @return bool * @throws DeleteException */ function delete($failSilently = false) { /** * @param \SplFileInfo $currentItem * @throws DeleteException */ $closure = function ($currentItem) use($failSilently) { if ($currentItem->isDir()) { $success = rmdir($currentItem->getRealPath()); if (!$success && !$failSilently) { throw new DeleteException($currentItem->getRealPath()); } } else { try { $file = new File($currentItem->getRealPath()); $file->delete(); } catch (DeleteException $e) { if (!$failSilently) { throw $e; } } } }; try { $this->iterate($closure, \RecursiveIteratorIterator::CHILD_FIRST); $success = rmdir($this); if (!$success && !$failSilently) { throw new DeleteException($this); } return $success; } catch (DeleteException $e) { throw $e; } }
/** * @covers Corgi\File\Directory::iterate * @depends testCreate */ public function testIterate() { $iterations = new \stdClass(); $iterations->flag = false; $closure = function () use($iterations) { $iterations->flag = true; }; $directory = new Directory(dirname($this->fullTestFilePath)); $file = new File($this->fullTestFilePath); $directory->create(); $file->touch(); $directory->iterate($closure); $file->delete(); $directory->delete(); $this->assertTrue($iterations->flag); }
/** * @covers Corgi\File\File::contents * @depends testTouch */ public function testGetContents() { $file = new File($this->fullTestFilePath); $this->assertInstanceOf('\\Corgi\\File\\ContentManagers\\FileContents', $file->contents()); }
public function tearDown() { $this->file->delete(); }