From 26600c2f59cf175e925a81b8ed875edb994e265c Mon Sep 17 00:00:00 2001 From: Worma Date: Fri, 1 Dec 2023 15:30:23 +0100 Subject: [PATCH 1/3] Use proper parameter type for NULL values --- src/Codeception/Lib/Driver/Db.php | 4 +++- tests/unit/Codeception/Module/Db/AbstractDbTest.php | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Codeception/Lib/Driver/Db.php b/src/Codeception/Lib/Driver/Db.php index b5680459..ae467496 100755 --- a/src/Codeception/Lib/Driver/Db.php +++ b/src/Codeception/Lib/Driver/Db.php @@ -290,7 +290,9 @@ public function executeQuery($query, array $params): PDOStatement $i = 0; foreach ($params as $param) { ++$i; - if (is_bool($param)) { + if (is_null($param)) { + $type = PDO::PARAM_NULL; + } elseif (is_bool($param)) { $type = PDO::PARAM_BOOL; } elseif (is_int($param)) { $type = PDO::PARAM_INT; diff --git a/tests/unit/Codeception/Module/Db/AbstractDbTest.php b/tests/unit/Codeception/Module/Db/AbstractDbTest.php index f880866b..9bd1e4b2 100644 --- a/tests/unit/Codeception/Module/Db/AbstractDbTest.php +++ b/tests/unit/Codeception/Module/Db/AbstractDbTest.php @@ -69,6 +69,11 @@ public function testSeeInDatabaseWithBinary() $this->module->seeInDatabase('users', ['uuid' => hex2bin('11edc34b01d972fa9c1d0242ac120006')]); } + public function testSeeInDatabaseWithNull() + { + $this->module->seeInDatabase('users', ['uuid' => null]); + } + public function testSeeInDatabase() { $this->module->seeInDatabase('users', ['name' => 'davert']); From 1c299b2b4c99ec078d88bc72d96663726d80bab5 Mon Sep 17 00:00:00 2001 From: Worma Date: Fri, 1 Dec 2023 15:30:30 +0100 Subject: [PATCH 2/3] Add direct dependency for mbstring extension because this package uses mb_detect_encoding() --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 2a777a15..26c633a0 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "require": { "php": "^8.0", "ext-json": "*", + "ext-mbstring": "*", "ext-pdo": "*", "codeception/codeception": "*@dev" }, From 956e7e549eb2c9ba8b25ef5c0efa798f50fddf83 Mon Sep 17 00:00:00 2001 From: Worma Date: Fri, 1 Dec 2023 16:48:27 +0100 Subject: [PATCH 3/3] Call isBinary() only if parameter is a string --- src/Codeception/Lib/Driver/Db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Codeception/Lib/Driver/Db.php b/src/Codeception/Lib/Driver/Db.php index ae467496..e83df570 100755 --- a/src/Codeception/Lib/Driver/Db.php +++ b/src/Codeception/Lib/Driver/Db.php @@ -296,7 +296,7 @@ public function executeQuery($query, array $params): PDOStatement $type = PDO::PARAM_BOOL; } elseif (is_int($param)) { $type = PDO::PARAM_INT; - } elseif ($this->isBinary($param)) { + } elseif (is_string($param) && $this->isBinary($param)) { $type = PDO::PARAM_LOB; } else { $type = PDO::PARAM_STR;