/** Test DirectoryIterator */
 public function testDirectoryIterator()
 {
     $dir = new DirectoryStreamEntity();
     $file = new FileStreamEntity();
     file_put_contents('virtual/abc/test.txt', 'Happy Pandas');
     $it = new DirectoryIterator('virtual');
     $cnt = 0;
     $path = '';
     foreach ($it as $item) {
         if ($cnt == 0) {
             $this->assertEquals('.', $item->getBasename());
             //                $this->assertTrue($item->isDot());
         } elseif ($cnt == 1) {
             $this->assertEquals('..', $item->getBasename());
             //                $this->assertTrue($item->isDot());
         } elseif ($cnt == 2) {
             $this->assertEquals('abc', $item->getBasename());
             $this->assertTrue($it->isDir());
             $this->assertFalse($it->isFile());
             $this->assertEquals($dir->getGid(), $it->getGroup());
             $this->assertEquals($dir->getUid(), $it->getOwner());
             $expected = sprintf('%o', $dir->getPermissions());
             $result = substr(sprintf('%o', $it->getPerms()), -3);
             $this->assertEquals($expected, $result);
             $path = $item->getPath() . DIRECTORY_SEPARATOR . $item->getBasename();
         }
         $cnt++;
     }
     $it = new DirectoryIterator($path);
     $it->seek(2);
     $item = $it->current();
     $this->assertEquals('test.txt', $item->getBasename());
     $this->assertFalse($item->isDir());
     $this->assertTrue($item->isFile());
     $this->assertEquals($file->getGid(), $item->getGroup());
     $this->assertEquals($file->getUid(), $item->getOwner());
     $expected = sprintf('%o', $file->getPermissions());
     $result = substr(sprintf('%o', $item->getPerms()), -3);
     $this->assertEquals($expected, $result);
 }
Esempio n. 2
0
 public function mkdir($path, $mode, $options)
 {
     if ($this->isOverride($path)) {
         return false;
     }
     $dlist = $this->getDirList($path);
     $overrides = $this->getOverridesInDir($path);
     $dlist = $this->dirsToStr($dlist, $overrides);
     $dir_entity = new DirectoryStreamEntity();
     $dir_entity->setPath($path);
     $dir_entity->setData($dlist);
     $dir_entity->openResource();
     $this->stream_overrides[$dir_entity->getPath()] = $dir_entity;
     foreach ($overrides as $v) {
         if (false === strpos($v, '.')) {
             mkdir("{$path}/{$v}");
         }
     }
     return true;
 }