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

Commit 87222e8

Browse files
committed
Fixes #316 : set return null for HydratingResultSet::current() on no data
1 parent d9b1af5 commit 87222e8

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/ResultSet/HydratingResultSet.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function getHydrator()
9090
/**
9191
* Iterator: get current item
9292
*
93-
* @return object
93+
* @return object|null
9494
*/
9595
public function current()
9696
{
@@ -99,14 +99,14 @@ public function current()
9999
} elseif (is_array($this->buffer) && isset($this->buffer[$this->position])) {
100100
return $this->buffer[$this->position];
101101
}
102-
$data = $this->dataSource->current();
103-
$object = is_array($data) ? $this->hydrator->hydrate($data, clone $this->objectPrototype) : false;
102+
$data = $this->dataSource->current();
103+
$current = is_array($data) ? $this->hydrator->hydrate($data, clone $this->objectPrototype) : null;
104104

105105
if (is_array($this->buffer)) {
106-
$this->buffer[$this->position] = $object;
106+
$this->buffer[$this->position] = $current;
107107
}
108108

109-
return $object;
109+
return $current;
110110
}
111111

112112
/**

test/unit/ResultSet/HydratingResultSetTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function testGetHydrator()
5656
/**
5757
* @covers \Zend\Db\ResultSet\HydratingResultSet::current
5858
*/
59-
public function testCurrent()
59+
public function testCurrentHasData()
6060
{
6161
$hydratingRs = new HydratingResultSet;
6262
$hydratingRs->initialize([
@@ -66,6 +66,17 @@ public function testCurrent()
6666
self::assertInstanceOf('ArrayObject', $obj);
6767
}
6868

69+
/**
70+
* @covers \Zend\Db\ResultSet\HydratingResultSet::current
71+
*/
72+
public function testCurrentDoesnotHasData()
73+
{
74+
$hydratingRs = new HydratingResultSet;
75+
$hydratingRs->initialize([]);
76+
$result = $hydratingRs->current();
77+
self::assertNull($result);
78+
}
79+
6980
/**
7081
* @covers \Zend\Db\ResultSet\HydratingResultSet::toArray
7182
* @todo Implement testToArray().

0 commit comments

Comments
 (0)