/** * @dataProvider provideArrayAccess */ public function testArrayAccess($paths, $batchSize, $options) { $options = array_merge(array('nb_fetches' => null, 'target' => null, 'iterate_result' => null), $options); $nbFetches = $options['nb_fetches']; $targets = (array) $options['target']; $iterateResult = $options['iterate_result']; $nodes = array(); foreach ($paths as $path) { $node = $this->getNodeMock(); $nodes[$path] = $node; } $this->objectManager->expects($this->exactly($nbFetches))->method('getNodesByPathAsArray')->will($this->returnCallback(function ($paths) use($nodes) { $ret = array(); foreach ($paths as $path) { $ret[$path] = $nodes[$path]; } return $ret; })); $nodes = new NodePathIterator($this->objectManager, $paths, null, null, $batchSize); if ($iterateResult) { for ($i = 0; $i < $iterateResult; $i++) { // if its not valid its at the end of the stack ... probably if (false === $nodes->valid()) { continue; } $nodes->current($nodes); $nodes->next($nodes); } } $res = array(); foreach ($targets as $target) { $res[$target] = $nodes[$target]; } }
public function testSeek() { $nodes = array(); $nodes2 = array(); foreach (array('p1', 'p2', 'p3') as $name) { $nodes[$name] = $this->getNodeMock(); } foreach (array('p8', 'p9') as $name) { $nodes2[$name] = $this->getNodeMock(); } $this->objectManager->expects($this->at(0))->method('getNodesByPathAsArray')->with(array('p1', 'p2', 'p3'))->will($this->returnValue($nodes)); $this->objectManager->expects($this->at(1))->method('getNodesByPathAsArray')->with(array('p8', 'p9'))->will($this->returnValue($nodes2)); $iterator = new NodePathIterator($this->objectManager, array('p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9'), null, null, 3); $iterator->seek(7); $iterator->valid(); $this->assertEquals($nodes2['p8'], $iterator->current()); }