From 172e0445bade166e7882616e6ed499fde515d106 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sat, 30 Oct 2021 08:18:34 +0200 Subject: [PATCH] Add unit test for the case "$v === null and $k has operator" For this code path: "elseif (preg_match('/\s*(!?=|<>|IS(?:\s+NOT)?)\s*$/i', $k ..." The above code path "elseif (! $this->hasOperator($k) ..." is covered in testOrWhereInClosure() and testOrWhereNotInClosure(). --- tests/system/Database/Builder/WhereTest.php | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/system/Database/Builder/WhereTest.php b/tests/system/Database/Builder/WhereTest.php index 653c837058aa..c84b7f4d5522 100644 --- a/tests/system/Database/Builder/WhereTest.php +++ b/tests/system/Database/Builder/WhereTest.php @@ -111,6 +111,28 @@ public function testWhereAssociateArray() $this->assertSame($expectedBinds, $builder->getBinds()); } + public function testWhereAssociateArrayKeyHasEqualValueIsNull() + { + $builder = $this->db->table('user'); + + $where = [ + 'id <' => 100, + 'col1 =' => null, + ]; + + $expectedSQL = 'SELECT * FROM "user" WHERE "id" < 100 AND "col1" IS NULL'; + $expectedBinds = [ + 'id' => [ + 100, + true, + ], + ]; + + $builder->where($where); + $this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect())); + $this->assertSame($expectedBinds, $builder->getBinds()); + } + public function testWhereCustomString() { $builder = $this->db->table('jobs');