From 24cb57cf92ae963db96f61bc94263c09bf167548 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Wed, 22 Jun 2016 16:08:29 +0900 Subject: [PATCH 1/3] fetchObject and fetchOne may return false --- src/ExtendedPdo.php | 4 ++-- src/ExtendedPdoInterface.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ExtendedPdo.php b/src/ExtendedPdo.php index 833dc71b..b9149c57 100644 --- a/src/ExtendedPdo.php +++ b/src/ExtendedPdo.php @@ -472,7 +472,7 @@ public function fetchCol( * * @param array $ctor_args Arguments to pass to the object constructor. * - * @return object + * @return object|false * */ public function fetchObject( @@ -537,7 +537,7 @@ public function fetchObjects( * * @param array $values Values to bind to the query. * - * @return array + * @return array|false * */ public function fetchOne($statement, array $values = array()) diff --git a/src/ExtendedPdoInterface.php b/src/ExtendedPdoInterface.php index da9918ad..4a56799a 100644 --- a/src/ExtendedPdoInterface.php +++ b/src/ExtendedPdoInterface.php @@ -114,7 +114,7 @@ public function fetchCol($statement, array $values = array(), $callable = null); * * @param array $ctor_args Arguments to pass to the object constructor. * - * @return object + * @return object|false * */ public function fetchObject( @@ -163,7 +163,7 @@ public function fetchObjects( * * @param array $values Values to bind to the query. * - * @return array + * @return array|false * */ public function fetchOne($statement, array $values = array()); From f392e575e0e1324a71d9c3059d43e08555bf145e Mon Sep 17 00:00:00 2001 From: DQNEO Date: Thu, 23 Jun 2016 17:43:23 +0900 Subject: [PATCH 2/3] added tests to assert fetchObject and fetchOne return false --- tests/AbstractExtendedPdoTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/AbstractExtendedPdoTest.php b/tests/AbstractExtendedPdoTest.php index 27575db9..a7bdbf16 100755 --- a/tests/AbstractExtendedPdoTest.php +++ b/tests/AbstractExtendedPdoTest.php @@ -333,6 +333,13 @@ public function testFetchObject() $this->assertSame('Anna', $actual->name); } + public function testFetchObjectReturningFalse() + { + $stm = "SELECT id, name FROM pdotest WHERE id = ?"; + $actual = $this->pdo->fetchObject($stm, array(-1)); + $this->assertSame(false, $actual); + } + public function testFetchObject_withCtorArgs() { $stm = "SELECT id, name FROM pdotest WHERE id = ?"; @@ -419,6 +426,13 @@ public function testFetchOne() $this->assertEquals($expect, $actual); } + public function testFetchOneReturningFalse() + { + $stm = "SELECT id, name FROM pdotest WHERE id = -1"; + $actual = $this->pdo->fetchOne($stm); + $this->assertSame(false, $actual); + } + public function testGroupSingleColumn() { $stm = "SELECT id, name FROM pdotest WHERE id = 1"; From d202410b4ff21bf047b938d17601fbe2969b9814 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Fri, 24 Jun 2016 10:22:15 +0900 Subject: [PATCH 3/3] use assertFalse --- tests/AbstractExtendedPdoTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/AbstractExtendedPdoTest.php b/tests/AbstractExtendedPdoTest.php index a7bdbf16..a059f9e3 100755 --- a/tests/AbstractExtendedPdoTest.php +++ b/tests/AbstractExtendedPdoTest.php @@ -337,7 +337,7 @@ public function testFetchObjectReturningFalse() { $stm = "SELECT id, name FROM pdotest WHERE id = ?"; $actual = $this->pdo->fetchObject($stm, array(-1)); - $this->assertSame(false, $actual); + $this->assertFalse($actual); } public function testFetchObject_withCtorArgs() @@ -430,7 +430,7 @@ public function testFetchOneReturningFalse() { $stm = "SELECT id, name FROM pdotest WHERE id = -1"; $actual = $this->pdo->fetchOne($stm); - $this->assertSame(false, $actual); + $this->assertFalse($actual); } public function testGroupSingleColumn()