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

Commit

Permalink
Merge branch 'hotfix/bartmcleod' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimuel committed Nov 30, 2017
2 parents ab816b7 + 75c7bcd commit a5c3270
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ResultSet/AbstractResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ public function key()
*/
public function current()
{
if (-1 === $this->buffer) {
// datasource was an array when the resultset was initialized
return $this->dataSource->current();
}

if ($this->buffer === null) {
$this->buffer = -2; // implicitly disable buffering from here on
} elseif (is_array($this->buffer) && isset($this->buffer[$this->position])) {
Expand Down
15 changes: 15 additions & 0 deletions test/ResultSet/ResultSetIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace ZendTest\Db\ResultSet;

use ArrayIterator;
use ArrayObject;
use PHPUnit\Framework\TestCase;
use SplStack;
use stdClass;
Expand Down Expand Up @@ -89,6 +90,20 @@ public function testCanProvideIteratorAsDataSource()
self::assertSame($it, $this->resultSet->getDataSource());
}

public function testCanProvideArrayAsDataSource()
{
$dataSource = [['foo']];
$this->resultSet->initialize($dataSource);
$this->assertEquals($dataSource[0], (array) $this->resultSet->current());

$returnType = new ArrayObject([], ArrayObject::ARRAY_AS_PROPS);
$dataSource = [$returnType];
$this->resultSet->setArrayObjectPrototype($returnType);
$this->resultSet->initialize($dataSource);
$this->assertEquals($dataSource[0], $this->resultSet->current());
$this->assertContains($dataSource[0], $this->resultSet);
}

public function testCanProvideIteratorAggregateAsDataSource()
{
$iteratorAggregate = $this->getMockBuilder('IteratorAggregate')
Expand Down

0 comments on commit a5c3270

Please sign in to comment.