Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Db::executeQuery() for null parameter #63

Merged
merged 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"require": {
"php": "^8.0",
"ext-json": "*",
"ext-mbstring": "*",
W0rma marked this conversation as resolved.
Show resolved Hide resolved
"ext-pdo": "*",
"codeception/codeception": "*@dev"
},
Expand Down
6 changes: 4 additions & 2 deletions src/Codeception/Lib/Driver/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,13 @@ 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;
} elseif ($this->isBinary($param)) {
} elseif (is_string($param) && $this->isBinary($param)) {
W0rma marked this conversation as resolved.
Show resolved Hide resolved
$type = PDO::PARAM_LOB;
} else {
$type = PDO::PARAM_STR;
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/Codeception/Module/Db/AbstractDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
Loading