Exemplo n.º 1
0
 /**
  * @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()));
 }
Exemplo n.º 2
0
 /**
  * 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;
     }
 }
Exemplo n.º 3
0
 /**
  * @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);
 }
Exemplo n.º 4
0
 /**
  * @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();
 }