diff --git a/lib/Db/AbstractResult.php b/lib/Db/AbstractResult.php index c1a60c6..fe4df26 100644 --- a/lib/Db/AbstractResult.php +++ b/lib/Db/AbstractResult.php @@ -17,15 +17,19 @@ abstract class AbstractResult implements Result { $out = array_shift($this->cur); $this->next(); return $out; + } else { + return null; } - $this->next(); - return null; } public function getRow() { - $out = ($this->valid() ? $this->cur : null); - $this->next(); - return $out; + if ($this->valid()) { + $out = $this->cur; + $this->next(); + return $out; + } else { + return null; + } } public function getAll(): array { diff --git a/lib/Db/ResultEmpty.php b/lib/Db/ResultEmpty.php new file mode 100644 index 0000000..f11d75e --- /dev/null +++ b/lib/Db/ResultEmpty.php @@ -0,0 +1,25 @@ + */ +class TestResultEmpty extends Test\AbstractTest { + + public function testGetChangeCountAndLastInsertId() { + $r = new Db\ResultEmpty; + $this->assertEquals(0, $r->changes()); + $this->assertEquals(0, $r->lastId()); + } + + public function testIterateOverResults() { + $rows = []; + foreach (new Db\ResultEmpty as $index => $row) { + $rows[$index] = $row['col']; + } + $this->assertEquals([], $rows); + } + + public function testGetSingleValues() { + $test = new Db\ResultEmpty; + $this->assertSame(null, $test->getValue()); + } + + public function testGetRows() { + $test = new Db\ResultEmpty; + $this->assertSame(null, $test->getRow()); + } + + public function testGetAllRows() { + $test = new Db\ResultEmpty; + $rows = []; + $this->assertEquals($rows, $test->getAll()); + } +} \ No newline at end of file diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 9d65e7b..3feab1b 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -56,6 +56,7 @@ Db/TestTransaction.php Db/TestResultAggregate.php + Db/TestResultEmpty.php Db/SQLite3/TestDbResultSQLite3.php Db/SQLite3/TestDbStatementSQLite3.php Db/SQLite3/TestDbDriverCreationSQLite3.php