Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 8276cf6

Browse files
bartmcleodezimuel
authored andcommitted
fixed that array should work out of the box as a source for ResultSet
1 parent 78c5fe9 commit 8276cf6

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/ResultSet/AbstractResultSet.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ public function key()
194194
*/
195195
public function current()
196196
{
197+
if (-1 === $this->buffer) {
198+
// datasource was an array when the resultset was initialized
199+
return $this->dataSource->current();
200+
}
201+
197202
if ($this->buffer === null) {
198203
$this->buffer = -2; // implicitly disable buffering from here on
199204
} elseif (is_array($this->buffer) && isset($this->buffer[$this->position])) {

test/ResultSet/ResultSetIntegrationTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ public function testCanProvideIteratorAsDataSource()
8989
self::assertSame($it, $this->resultSet->getDataSource());
9090
}
9191

92+
public function testCanProvideArrayAsDataSource()
93+
{
94+
$dataSource = [['foo']];
95+
$this->resultSet->initialize($dataSource);
96+
$this->assertEquals($dataSource[0], (array) $this->resultSet->current());
97+
98+
$returnType = new ReturnType();
99+
$dataSource = [$returnType];
100+
$this->resultSet->setArrayObjectPrototype($returnType);
101+
$this->resultSet->initialize($dataSource);
102+
$this->assertEquals($dataSource[0], $this->resultSet->current());
103+
$this->assertContains($dataSource[0], $this->resultSet);
104+
}
105+
92106
public function testCanProvideIteratorAggregateAsDataSource()
93107
{
94108
$iteratorAggregate = $this->getMockBuilder('IteratorAggregate')

test/ResultSet/ReturnType.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
4+
namespace ZendTest\Db\ResultSet;
5+
6+
7+
class ReturnType
8+
{
9+
public function exchangeArray(array $values)
10+
{
11+
12+
}
13+
}

0 commit comments

Comments
 (0)