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

Fixes #316 : set return null for HydratingResultSet::current() on no data #325

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ All notable changes to this project will be documented in this file, in reverse

### Changed

- Nothing.
- [#325](https://github.com/zendframework/zend-db/pull/325) change `HydratingResultSet::current()` to returns null on no data.

### Deprecated

Expand Down Expand Up @@ -425,4 +425,4 @@ All notable changes to this project will be documented in this file, in reverse
closure binding (now that we're on 5.5+, this is possible).
- [#9](https://github.com/zendframework/zend-db/pull/9) thoroughly audits the
OCI8 (Oracle) driver, ensuring it provides feature parity with other drivers,
and fixes issues with subselects, limits, and offsets.
and fixes issues with subselects, limits, and offsets.
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