Skip to content

Commit 4b4775d

Browse files
committed
NOT IN parameters are not adding parenthesis automatically
1 parent bc9b2f5 commit 4b4775d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tests/Mouf/Database/MagicQueryTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ public function testStandardSelect()
7878
$sql = 'SELECT * FROM users WHERE status IN :statuses';
7979
$this->assertEquals('SELECT * FROM users WHERE status IN (\'1\',\'2\')', self::simplifySql($magicQuery->build($sql, ['statuses' => [1, 2]])));
8080

81+
$sql = 'SELECT * FROM users WHERE status not in :status';
82+
$this->assertEquals("SELECT * FROM users WHERE status NOT IN ('2','4')", self::simplifySql($magicQuery->build($sql, ['status' => [2, 4]])));
83+
84+
$sql = 'SELECT * FROM users WHERE status not in (:status)';
85+
$this->assertEquals("SELECT * FROM users WHERE status NOT IN ('2','4')", self::simplifySql($magicQuery->build($sql, ['status' => [2, 4]])));
86+
8187
$sql = 'SELECT * FROM myTable where someField BETWEEN :value1 AND :value2';
8288
$this->assertEquals("SELECT * FROM myTable WHERE someField BETWEEN '2' AND '4'", self::simplifySql($magicQuery->build($sql, ['value1' => 2, 'value2' => 4])));
8389
$this->assertEquals("SELECT * FROM myTable WHERE someField >= '2'", self::simplifySql($magicQuery->build($sql, ['value1' => 2])));
@@ -433,5 +439,9 @@ public function testBuildPreparedStatement()
433439
// Let's check that MagicQuery is cleverly adding parenthesis if the user forgot those in the "IN" statement.
434440
$sql = 'SELECT id FROM users WHERE status IN :status';
435441
$this->assertEquals("SELECT id FROM users WHERE status IN (:status)", self::simplifySql($magicQuery->buildPreparedStatement($sql, ['status' => [1,2]])));
442+
443+
// Let's check that MagicQuery is cleverly adding parenthesis if the user forgot those in the "NOT IN" statement.
444+
$sql = 'SELECT id FROM users WHERE status NOT IN :status';
445+
$this->assertEquals("SELECT id FROM users WHERE status NOT IN (:status)", self::simplifySql($magicQuery->buildPreparedStatement($sql, ['status' => [1,2]])));
436446
}
437447
}

0 commit comments

Comments
 (0)