/**
  * @dataProvider iteratorDataProvider
  */
 public function testIterateTwice(array $expectations, array $expectedItems)
 {
     $this->expectIteratorCalls($expectations);
     $actualItems = array();
     $this->iterator->rewind();
     while ($this->iterator->valid()) {
         $actualItems[$this->iterator->key()] = $this->iterator->current();
         $this->iterator->next();
     }
     $this->assertEquals($expectedItems, $actualItems);
     $this->expectIteratorCalls($expectations);
     $actualItems = array();
     $this->iterator->rewind();
     while ($this->iterator->valid()) {
         $actualItems[$this->iterator->key()] = $this->iterator->current();
         $this->iterator->next();
     }
     $this->assertEquals($expectedItems, $actualItems);
 }
Example #2
0
 /**
  * @covers Basics\Collection\TypedList::key
  * @covers Basics\Collection\TypedList::current
  * @covers Basics\Collection\TypedList::next
  * @covers Basics\Collection\TypedList::valid
  * @covers Basics\Collection\TypedList::rewind
  */
 public function testIteratorInterfaceWorksProperly()
 {
     $this->expectSuccessiveCallsOnIsExpectedType(3, true);
     $item0 = $this->expectItem();
     $item1 = $this->expectItem();
     $item2 = $this->expectItem();
     $this->typedList->add($item0);
     $this->typedList->add($item1);
     $this->typedList->add($item2);
     $this->assertIndexValidAndHoldsExpectedItem(0, $item0);
     $this->typedList->next();
     $this->assertIndexValidAndHoldsExpectedItem(1, $item1);
     $this->typedList->next();
     $this->assertIndexValidAndHoldsExpectedItem(2, $item2);
     // now, invalid position...
     $this->typedList->next();
     $this->assertAttributeSame(3, 'position', $this->typedList);
     $this->assertFalse($this->typedList->valid());
     $this->assertSame(3, $this->typedList->key());
     // start at the beginning
     $this->typedList->rewind();
     $this->assertAttributeSame(0, 'position', $this->typedList);
     $this->assertIndexValidAndHoldsExpectedItem(0, $item0);
 }