/** * Fetch the node managed by this definition * * @access public * @return Faker\Components\Engine\Common\Composite\CompositeInterface the new node */ public function getNode() { if ($this->dataIterator === null && !empty($this->dataClosure)) { $this->dataIterator = $this->dataClosure->__invoke(); } $source = new PHPDatasource(); $source->setIterator($this->dataIterator); return $source; }
public function testDatasourceInterfaceImplementation() { $iterator = new \ArrayIterator(); $iterator->append(array('value' => 1)); $iterator->append(array('value' => 2)); $iterator->append(array('value' => 3)); $iterator->append(array('value' => 4)); $iterator->append(array('value' => 5)); $iterator->append(array('value' => 6)); $mock = new PHPDatasource(); $mock->setIterator($iterator); $mock->setOption('name', 'unique_source_1'); $mock->validate(); # no error thrown as we have an iterator $mock->initSource(); $this->assertEquals($mock->fetchOne(), array('value' => 1)); $this->assertEquals($mock->fetchOne(), array('value' => 1)); $mock->flushSource(); $this->assertEquals($mock->fetchOne(), array('value' => 2)); $mock->flushSource(); $this->assertEquals($mock->fetchOne(), array('value' => 3)); $mock->cleanupSource(); $this->assertEquals($mock->fetchOne(), array('value' => 1)); }