/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage wrongColumnsNumber */ public function testIteratorInterface() { $this->assertSame(-1, $this->_model->key()); $this->assertFalse($this->_model->valid()); $this->_model->expects($this->exactly(4))->method('_getNextRow')->will($this->onConsecutiveCalls([1, 2, 3], [4, 5, 5], [6, 7, 8])); $data = []; foreach ($this->_model as $key => $value) { $data[$key] = $value; } $this->assertSame([['key1' => 1, 'key2' => 2, 'key3' => 3], ['key1' => 4, 'key2' => 5, 'key3' => 5], ['key1' => 6, 'key2' => 7, 'key3' => 8]], $data); $this->_model->current(); }
public function testIteratorInterface() { $this->assertSame(array('key1' => '', 'key2' => '', 'key3' => ''), $this->_model->current()); $this->assertSame(-1, $this->_model->key()); $this->assertFalse($this->_model->valid()); $this->_model->expects($this->exactly(4))->method('_getNextRow')->will($this->onConsecutiveCalls(array(1, 2, 3), array(4, 5), array(6, 7, 8), false)); $data = array(); foreach ($this->_model as $key => $value) { $data[$key] = $value; } $this->assertSame(array(array('key1' => 1, 'key2' => 2, 'key3' => 3), array('key1' => 4, 'key2' => 5, 'key3' => ''), array('key1' => 6, 'key2' => 7, 'key3' => 8)), $data); }
/** * Asserts a certain item at a certain index of the typed list. * * @param int $index The index of the expected item. * @param Item $item The item expected at index. */ private function assertIndexValidAndHoldsExpectedItem($index, Item $item) { $this->assertAttributeSame($index, 'position', $this->typedList); $this->assertSame($index, $this->typedList->key()); $this->assertTrue($this->typedList->valid()); $this->assertSame($item, $this->typedList->current()); }
/** * @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); }