From cc23e1ea2f38431b32b1a3af3561f86b1b9f27d8 Mon Sep 17 00:00:00 2001 From: Maxim Smakouz Date: Wed, 29 Nov 2023 19:16:56 +0200 Subject: [PATCH] Add tests with different operators --- src/Driver/Compiler.php | 2 +- .../Driver/Common/Query/SelectQueryTest.php | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/Driver/Compiler.php b/src/Driver/Compiler.php index d5fbc80e..f08dda93 100644 --- a/src/Driver/Compiler.php +++ b/src/Driver/Compiler.php @@ -475,7 +475,7 @@ protected function condition(QueryParameters $params, Quoter $q, array $context) $placeholder = '?'; if ($value->isArray()) { - return $this->arrayToInOperator($params, $q, $value->getValue(), $operator === 'IN'); + return $this->arrayToInOperator($params, $q, $value->getValue(), $operator === 'IN' || $operator === '='); } if ($value->isNull()) { diff --git a/tests/Database/Functional/Driver/Common/Query/SelectQueryTest.php b/tests/Database/Functional/Driver/Common/Query/SelectQueryTest.php index c0cc74a3..8c3caa40 100644 --- a/tests/Database/Functional/Driver/Common/Query/SelectQueryTest.php +++ b/tests/Database/Functional/Driver/Common/Query/SelectQueryTest.php @@ -2166,6 +2166,62 @@ public function testSelectWithFragmentedColumns(): void ); } + public function testWhereInWithoutSpecifiedOperator(): void + { + $select = $this->database + ->select() + ->from(['users']) + ->where( + 'uuid', + new Parameter(['12345678-1234-1234-1234-123456789012', '12345678-1234-1234-1234-123456789013']) + ); + + $this->assertSameQuery('SELECT * FROM {users} WHERE {uuid} IN (?, ?)', $select); + + $this->assertSameParameters( + ['12345678-1234-1234-1234-123456789012', '12345678-1234-1234-1234-123456789013'], + $select, + ); + } + + public function testWhereInWithEqualSpecifiedOperator(): void + { + $select = $this->database + ->select() + ->from(['users']) + ->where( + 'uuid', + '=', + new Parameter(['12345678-1234-1234-1234-123456789012', '12345678-1234-1234-1234-123456789013']) + ); + + $this->assertSameQuery('SELECT * FROM {users} WHERE {uuid} IN (?, ?)', $select); + + $this->assertSameParameters( + ['12345678-1234-1234-1234-123456789012', '12345678-1234-1234-1234-123456789013'], + $select, + ); + } + + public function testWhereInWithNotEqualSpecifiedOperator(): void + { + $select = $this->database + ->select() + ->from(['users']) + ->where( + 'uuid', + '!=', + new Parameter(['12345678-1234-1234-1234-123456789012', '12345678-1234-1234-1234-123456789013']) + ); + + $this->assertSameQuery('SELECT * FROM {users} WHERE {uuid} NOT IN (?, ?)', $select); + + $this->assertSameParameters( + ['12345678-1234-1234-1234-123456789012', '12345678-1234-1234-1234-123456789013'], + $select, + ); + } + public function testFragmentInWhereInClause(): void { $select = $this->database