/** * @covers Corgi\File\Base\FileSystemNode::getPath */ public function testGetPath() { $file = new File($this->fullTestFilePath); $file->touch(); $this->assertInternalType('string', $file->getPath()); $file->delete(); $directory = new Directory($this->fullTestFilePath); $directory->create(); $this->assertInternalType('string', $directory->getPath()); $directory->delete(); }
/** * 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::delete * @depends testTouch */ public function testDelete() { $file = new File($this->fullTestFilePath); $file->touch(); $this->assertBool($file->delete()); }
public function tearDown() { $this->file->delete(); }