/**
  * test method to be used for iterating
  *
  * @test
  */
 public function iteration()
 {
     $dir = new vfsStreamDirectory('foo');
     $mockChild1 = $this->getMock('org\\bovigo\\vfs\\vfsStreamContent');
     $mockChild1->expects($this->any())->method('getName')->will($this->returnValue('bar'));
     $dir->addChild($mockChild1);
     $mockChild2 = $this->getMock('org\\bovigo\\vfs\\vfsStreamContent');
     $mockChild2->expects($this->any())->method('getName')->will($this->returnValue('baz'));
     $dir->addChild($mockChild2);
     $dirIterator = $dir->getIterator();
     $this->assertEquals('bar', $dirIterator->key());
     $this->assertTrue($dirIterator->valid());
     $bar = $dirIterator->current();
     $this->assertSame($mockChild1, $bar);
     $dirIterator->next();
     $this->assertEquals('baz', $dirIterator->key());
     $this->assertTrue($dirIterator->valid());
     $baz = $dirIterator->current();
     $this->assertSame($mockChild2, $baz);
     $dirIterator->next();
     $this->assertFalse($dirIterator->valid());
     $this->assertNull($dirIterator->key());
     $this->assertNull($dirIterator->current());
     $dirIterator->rewind();
     $this->assertTrue($dirIterator->valid());
     $this->assertEquals('bar', $dirIterator->key());
     $bar2 = $dirIterator->current();
     $this->assertSame($mockChild1, $bar2);
 }
Exemplo n.º 2
0
 /**
  * opens a directory
  *
  * @param   string  $path
  * @param   int     $options
  * @return  bool
  */
 public function dir_opendir($path, $options)
 {
     $path = $this->resolvePath(vfsStream::path($path));
     $this->dir = $this->getContentOfType($path, vfsStreamContent::TYPE_DIR);
     if (null === $this->dir) {
         return false;
     }
     $this->dirIterator = $this->dir->getIterator();
     return true;
 }
Exemplo n.º 3
0
 /**
  * opens a directory
  *
  * @param   string  $path
  * @param   int     $options
  * @return  bool
  */
 public function dir_opendir($path, $options)
 {
     $path = $this->resolvePath(vfsStream::path($path));
     $this->dir = $this->getContentOfType($path, vfsStreamContent::TYPE_DIR);
     if (null === $this->dir || $this->dir->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) {
         return false;
     }
     $this->dirIterator = $this->dir->getIterator();
     return true;
 }