/**
  * @test
  */
 function iteration()
 {
     $reader = new XMLReaderStub('<!-- comment --><root><child></child></root>');
     $it = new XMLChildElementIterator($reader);
     $this->assertEquals(false, $it->valid());
     $this->assertSame(null, $it->valid());
     $it->rewind();
     $this->assertEquals(true, $it->valid());
     $this->assertEquals('child', $it->current()->getName());
     $it->next();
     $this->assertEquals(false, $it->valid());
     $reader = new XMLReaderStub('<root><none></none><one><child></child></one><none></none></root>');
     $base = new XMLElementIterator($reader);
     $base->rewind();
     $root = $base->current();
     $this->assertEquals('root', $root->getName());
     $children = $root->getChildElements();
     $this->assertEquals('root', $reader->name);
     $children->rewind();
     $this->assertEquals('none', $reader->name);
     $children->next();
     $this->assertEquals('one', $reader->name);
     $childChildren = new XMLChildElementIterator($reader);
     $this->assertEquals('child', $childChildren->current()->getName());
     $childChildren->next();
     $this->assertEquals(false, $childChildren->valid());
     $this->assertEquals('none', $reader->name);
     $childChildren->next();
     $this->assertEquals('none', $reader->name);
     $this->assertEquals(true, $children->valid());
     $children->next();
     $this->assertEquals(false, $children->valid());
     // children w/o descendants
     $reader->rewind();
     $expected = array('none', 'one', 'none');
     $root = $base->current();
     $this->assertEquals('root', $root->getName());
     $index = 0;
     $count = 0;
     foreach ($root->getChildElements() as $index => $child) {
         $this->assertSame($count++, $index);
         $this->assertEquals($expected[$index], $reader->name);
     }
     $this->assertEquals(count($expected), $count);
     // children w/ descendants
     $reader->rewind();
     $expected = array('none', 'one', 'child', 'none');
     $root = $base->current();
     $this->assertEquals('root', $root->getName());
     $index = 0;
     $count = 0;
     foreach ($root->getChildElements(null, true) as $index => $child) {
         $this->assertSame($count++, $index);
         $this->assertEquals($expected[$index], $reader->name);
     }
     $this->assertEquals(count($expected), $count);
 }
 /**
  * @test
  */
 function iterateOverNamedElements()
 {
     $reader = new XMLReaderStub('<r><a>1</a><a>2</a><b>c</b><a>3</a></r>');
     $it = new XMLElementIterator($reader, 'a');
     $this->assertEquals(null, $it->valid());
     $it->rewind();
     $this->assertEquals(true, $it->valid());
     $this->assertEquals('a', $it->current()->getName());
     $it->next();
     $this->assertEquals('a', $it->current()->getName());
     $it->next();
     $this->assertEquals('a', $it->current()->getName());
     $this->assertEquals('3', $it);
     $it->next();
     $this->assertEquals(false, $it->valid());
 }
 /**
  * @return XMLReaderNode|null
  */
 public function current()
 {
     $this->didRewind || self::rewind();
     return parent::current();
 }