diff --git a/CHANGELOG.md b/CHANGELOG.md index a9cfa85cd9..b0a897b605 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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. \ No newline at end of file diff --git a/src/ResultSet/HydratingResultSet.php b/src/ResultSet/HydratingResultSet.php index b927fc9f72..993777da54 100644 --- a/src/ResultSet/HydratingResultSet.php +++ b/src/ResultSet/HydratingResultSet.php @@ -90,7 +90,7 @@ public function getHydrator() /** * Iterator: get current item * - * @return object + * @return object|null */ public function current() { @@ -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; } /** diff --git a/test/unit/ResultSet/HydratingResultSetTest.php b/test/unit/ResultSet/HydratingResultSetTest.php index 528f029da7..8b6e00c531 100644 --- a/test/unit/ResultSet/HydratingResultSetTest.php +++ b/test/unit/ResultSet/HydratingResultSetTest.php @@ -56,7 +56,7 @@ public function testGetHydrator() /** * @covers \Zend\Db\ResultSet\HydratingResultSet::current */ - public function testCurrent() + public function testCurrentHasData() { $hydratingRs = new HydratingResultSet; $hydratingRs->initialize([ @@ -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().