public function testPointerIteration() { $this->assertEquals($this->_0, $this->collection->next()); $this->assertEquals($this->_1, $this->collection->next()); $this->assertEquals($this->_2, $this->collection->next()); $this->assertEquals($this->_3, $this->collection->next()); $this->assertEquals(null, $this->collection->next()); $this->assertEquals($this->_3, $this->collection->previous()); $this->assertEquals($this->_2, $this->collection->previous()); $this->assertEquals($this->_1, $this->collection->previous()); $this->assertEquals($this->_0, $this->collection->previous()); $this->assertEquals(null, $this->collection->previous()); $this->collection->setPointer(2); $this->assertEquals($this->_2, $this->collection->current()); }
public function testIterator() { $nodeData = array('alpha', 'alpha/a', 'alpha/a/b', 'alpha/a/b/c'); $nodes = array(); $c = new Collection(); foreach ($nodeData as $path) { $n = new Node($path); $nodes[$path] = $n; $c->addNode($n); } $c->rewind(); $this->assertEquals($nodes['alpha'], $c->current()); $this->assertEquals('alpha', $c->key()); $this->assertEquals(true, $c->valid()); $c->next(); $this->assertEquals($nodes['alpha/a'], $c->current()); $this->assertEquals('alpha/a', $c->key()); $this->assertEquals(true, $c->valid()); $c->next(); $this->assertEquals($nodes['alpha/a/b'], $c->current()); $this->assertEquals('alpha/a/b', $c->key()); $this->assertEquals(true, $c->valid()); $c->next(); $this->assertEquals($nodes['alpha/a/b/c'], $c->current()); $this->assertEquals('alpha/a/b/c', $c->key()); $this->assertEquals(true, $c->valid()); $c->next(); $this->assertEquals(false, $c->valid()); $c->rewind(); $this->assertEquals($nodes['alpha'], $c->current()); $this->assertEquals('alpha', $c->key()); $this->assertEquals(true, $c->valid()); }
/** * Moves the internal iterator position to the next element. */ public function next() { return $this->coll->next(); }