From 527ecee3938778426d6524dfb7e65044d3c6250f Mon Sep 17 00:00:00 2001 From: "J. King" Date: Thu, 29 Nov 2018 13:56:15 -0500 Subject: [PATCH] Code coverage fixes --- lib/Db/PDODriver.php | 2 +- lib/Db/PDOStatement.php | 2 +- lib/Db/PostgreSQL/PDOStatement.php | 9 +++++---- tests/cases/Db/PostgreSQL/TestStatement.php | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/Db/PDODriver.php b/lib/Db/PDODriver.php index 0eedd6bd..e418cdca 100644 --- a/lib/Db/PDODriver.php +++ b/lib/Db/PDODriver.php @@ -28,9 +28,9 @@ trait PDODriver { } $changes = $r->rowCount(); try { + $lastId = 0; $lastId = ($changes) ? $this->db->lastInsertId() : 0; } catch (\PDOException $e) { // @codeCoverageIgnore - $lastId = 0; } return new PDOResult($r, [$changes, $lastId]); } diff --git a/lib/Db/PDOStatement.php b/lib/Db/PDOStatement.php index dca020fd..26a50458 100644 --- a/lib/Db/PDOStatement.php +++ b/lib/Db/PDOStatement.php @@ -42,9 +42,9 @@ class PDOStatement extends AbstractStatement { } $changes = $this->st->rowCount(); try { + $lastId = 0; $lastId = ($changes) ? $this->db->lastInsertId() : 0; } catch (\PDOException $e) { // @codeCoverageIgnore - $lastId = 0; } return new PDOResult($this->st, [$changes, $lastId]); } diff --git a/lib/Db/PostgreSQL/PDOStatement.php b/lib/Db/PostgreSQL/PDOStatement.php index 9d584d00..450ebab4 100644 --- a/lib/Db/PostgreSQL/PDOStatement.php +++ b/lib/Db/PostgreSQL/PDOStatement.php @@ -42,12 +42,13 @@ class PDOStatement extends \JKingWeb\Arsse\Db\AbstractStatement { parent::retypeArray($bindings, $append); $this->qMunged = self::mungeQuery($this->qOriginal, $this->types, false); try { + // statement creation with PostgreSQL should never fail (it is not evaluated at creation time) $s = $this->db->prepare($this->qMunged); - $this->st = new \JKingWeb\Arsse\Db\PDOStatement($this->db, $s, $this->bindings); - } catch (\PDOException $e) { - list($excClass, $excMsg, $excData) = $this->exceptionBuild(true); - throw new $excClass($excMsg, $excData); + } catch (\PDOException $e) { // @codeCoverageIgnore + list($excClass, $excMsg, $excData) = $this->exceptionBuild(true); // @codeCoverageIgnore + throw new $excClass($excMsg, $excData); // @codeCoverageIgnore } + $this->st = new \JKingWeb\Arsse\Db\PDOStatement($this->db, $s, $this->bindings); } return true; } diff --git a/tests/cases/Db/PostgreSQL/TestStatement.php b/tests/cases/Db/PostgreSQL/TestStatement.php index 5066b9a3..d5f8b9d8 100644 --- a/tests/cases/Db/PostgreSQL/TestStatement.php +++ b/tests/cases/Db/PostgreSQL/TestStatement.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse\TestCase\Db\PostgreSQL; /** - * @covers \JKingWeb\Arsse\Db\PDOStatement + * @covers \JKingWeb\Arsse\Db\PostgreSQL\PDOStatement * @covers \JKingWeb\Arsse\Db\PDOError */ class TestStatement extends \JKingWeb\Arsse\TestCase\Db\BaseStatement { protected static $implementation = "PDO PostgreSQL";