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

Commit

Permalink
Fixes #316 : set return null for HydratingResultSet::current() on no …
Browse files Browse the repository at this point in the history
…data
  • Loading branch information
samsonasik committed Jul 3, 2018
1 parent 58271ef commit 06ab96b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/ResultSet/HydratingResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function getHydrator()
/**
* Iterator: get current item
*
* @return object
* @return object|null
*/
public function current()
{
Expand All @@ -99,14 +99,14 @@ public function current()
} elseif (is_array($this->buffer) && isset($this->buffer[$this->position])) {
return $this->buffer[$this->position];
}
$data = $this->dataSource->current();
$object = is_array($data) ? $this->hydrator->hydrate($data, clone $this->objectPrototype) : false;
$data = $this->dataSource->current();
$current = is_array($data) ? $this->hydrator->hydrate($data, clone $this->objectPrototype) : null;

if (is_array($this->buffer)) {
$this->buffer[$this->position] = $object;
$this->buffer[$this->position] = $current;
}

return $object;
return $current;
}

/**
Expand Down
13 changes: 12 additions & 1 deletion test/unit/ResultSet/HydratingResultSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testGetHydrator()
/**
* @covers \Zend\Db\ResultSet\HydratingResultSet::current
*/
public function testCurrent()
public function testCurrentHasData()
{
$hydratingRs = new HydratingResultSet;
$hydratingRs->initialize([
Expand All @@ -66,6 +66,17 @@ public function testCurrent()
self::assertInstanceOf('ArrayObject', $obj);
}

/**
* @covers \Zend\Db\ResultSet\HydratingResultSet::current
*/
public function testCurrentDoesnotHasData()
{
$hydratingRs = new HydratingResultSet;
$hydratingRs->initialize([]);
$result = $hydratingRs->current();
self::assertNull($result);
}

/**
* @covers \Zend\Db\ResultSet\HydratingResultSet::toArray
* @todo Implement testToArray().
Expand Down

0 comments on commit 06ab96b

Please sign in to comment.