mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Add ResultEmpty class
This allows for the creation of synthetic empty result sets
This commit is contained in:
parent
2037efce61
commit
5d4ea6edc0
4 changed files with 72 additions and 5 deletions
|
@ -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 {
|
||||
|
|
25
lib/Db/ResultEmpty.php
Normal file
25
lib/Db/ResultEmpty.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
/** @license MIT
|
||||
* Copyright 2017 J. King, Dustin Wilson et al.
|
||||
* See LICENSE and AUTHORS files for details */
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace JKingWeb\Arsse\Db;
|
||||
|
||||
use JKingWeb\Arsse\Db\Exception;
|
||||
|
||||
class ResultEmpty extends AbstractResult {
|
||||
public function changes() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function lastId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// PHP iterator methods
|
||||
|
||||
public function valid() {
|
||||
return false;
|
||||
}
|
||||
}
|
37
tests/Db/TestResultEmpty.php
Normal file
37
tests/Db/TestResultEmpty.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace JKingWeb\Arsse;
|
||||
|
||||
/** @covers \JKingWeb\Arsse\Db\ResultEmpty<extended> */
|
||||
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());
|
||||
}
|
||||
}
|
|
@ -56,6 +56,7 @@
|
|||
<testsuite name="Database drivers">
|
||||
<file>Db/TestTransaction.php</file>
|
||||
<file>Db/TestResultAggregate.php</file>
|
||||
<file>Db/TestResultEmpty.php</file>
|
||||
<file>Db/SQLite3/TestDbResultSQLite3.php</file>
|
||||
<file>Db/SQLite3/TestDbStatementSQLite3.php</file>
|
||||
<file>Db/SQLite3/TestDbDriverCreationSQLite3.php</file>
|
||||
|
|
Loading…
Reference in a new issue