Пример #1
0
 function testIteratorForeach()
 {
     $stack = new LinkedStack();
     $stack->push(1);
     $stack->push(2);
     $stack->push(3);
     $stack->push(4);
     $iterator = $stack->getIterator();
     $this->assertInstanceOf('Collections\\LinkedStackIterator', $iterator);
     $this->assertCount(4, $iterator);
     $expectedKey = 0;
     $expectedValue = 4;
     $iterator->rewind();
     for ($i = 0; $i < 4; $i++) {
         $this->assertTrue($iterator->valid());
         $this->assertEquals($expectedKey++, $iterator->key());
         $this->assertEquals($expectedValue--, $iterator->current());
         $iterator->next();
     }
     $this->assertFalse($iterator->valid());
 }