From afe728d07af4fc247abc4aa1cbe4a92d604beb35 Mon Sep 17 00:00:00 2001 From: Jan Pecha Date: Sat, 22 Jul 2017 11:14:39 +0200 Subject: [PATCH] Result::fetch() removed typehint (#257) --- src/Dibi/Result.php | 3 ++- tests/dibi/Connection.fetch.phpt | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Dibi/Result.php b/src/Dibi/Result.php index c6d379d4..11030dc5 100644 --- a/src/Dibi/Result.php +++ b/src/Dibi/Result.php @@ -162,8 +162,9 @@ class Result implements IDataSource /** * Fetches the row at current position, process optional type conversion. * and moves the internal cursor to the next position + * @return ?Row|array */ - final public function fetch(): ?Row + final public function fetch() { $row = $this->getResultDriver()->fetch(true); if ($row === null) { diff --git a/tests/dibi/Connection.fetch.phpt b/tests/dibi/Connection.fetch.phpt index 691d5d7b..7b2a01e8 100644 --- a/tests/dibi/Connection.fetch.phpt +++ b/tests/dibi/Connection.fetch.phpt @@ -52,6 +52,15 @@ Assert::equal([ ], iterator_to_array($res)); +// fetch row by row as array +$res = $conn->query('SELECT * FROM [products] ORDER BY product_id')->setRowClass(null); +Assert::equal([ + ['product_id' => num(1), 'title' => 'Chair'], + ['product_id' => num(2), 'title' => 'Table'], + ['product_id' => num(3), 'title' => 'Computer'], +], iterator_to_array($res)); + + // fetch complete result set like association array $res = $conn->query('SELECT * FROM [products] ORDER BY product_id'); Assert::equal([