From aa4f09ce93e9375565d27afe44e4522ef0ee335a Mon Sep 17 00:00:00 2001 From: Paul Chubatyy Date: Tue, 28 Aug 2012 01:22:48 +0300 Subject: [PATCH 1/3] Add the in and notIn methods to Expression builder. Unit tests applied. --- .../Query/Expression/ExpressionBuilder.php | 26 +++++++++++++++++++ .../Expression/ExpressionBuilderTest.php | 10 +++++++ 2 files changed, 36 insertions(+) mode change 100644 => 100755 lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php mode change 100644 => 100755 tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php diff --git a/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php b/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php old mode 100644 new mode 100755 index 4f50232844e..cab817c8f7e --- a/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php +++ b/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php @@ -249,6 +249,32 @@ public function like($x, $y) return $this->comparison($x, 'LIKE', $y); } + /** + * Creates a IN () comparison expression with the given arguments. + * + * @param string $x field in string format to be inspected by IN() comparison. + * @param array $y Array of values to be used by IN() comparison. + * + * @return string + */ + public function in($x, array $y) + { + return $this->comparison($x, 'IN', '('.implode(', ', $y).')'); + } + + /** + * Creates a NOT IN () comparison expression with the given arguments. + * + * @param string $x field in string format to be inspected by NOT IN() comparison. + * @param array $y Array of values to be used by NOT IN() comparison. + * + * @return string + */ + public function notIn($x, array $y) + { + return $this->comparison($x, 'NOT IN', '('.implode(', ', $y).')'); + } + /** * Quotes a given input parameter. * diff --git a/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php old mode 100644 new mode 100755 index 1893e97faf7..da2e5cdccff --- a/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php @@ -198,4 +198,14 @@ public function testIsNotNull() { $this->assertEquals('u.updated IS NOT NULL', $this->expr->isNotNull('u.updated')); } + + public function testIn() + { + $this->assertEquals('u.groups IN (1,3,4,7)', $this->expr->in('u.groups', array(1,3,4,7))); + } + + public function testNotIn() + { + $this->assertEquals('u.groups NOT IN (1,3,4,7)', $this->expr->notIn('u.groups', array(1,3,4,7))); + } } \ No newline at end of file From 802109c039afa794cdf95da6604013339c2e480c Mon Sep 17 00:00:00 2001 From: Paul Chubatyy Date: Tue, 28 Aug 2012 11:26:52 +0300 Subject: [PATCH 2/3] Fixed the test. --- .../Tests/DBAL/Query/Expression/ExpressionBuilderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php index da2e5cdccff..d09bb113e6d 100755 --- a/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php @@ -201,11 +201,11 @@ public function testIsNotNull() public function testIn() { - $this->assertEquals('u.groups IN (1,3,4,7)', $this->expr->in('u.groups', array(1,3,4,7))); + $this->assertEquals('u.groups IN (1, 3, 4, 7)', $this->expr->in('u.groups', array(1,3,4,7))); } public function testNotIn() { - $this->assertEquals('u.groups NOT IN (1,3,4,7)', $this->expr->notIn('u.groups', array(1,3,4,7))); + $this->assertEquals('u.groups NOT IN (1, 3, 4, 7)', $this->expr->notIn('u.groups', array(1,3,4,7))); } } \ No newline at end of file From f812cc8c110fb9213fc83ce16cdab8c738d25b2c Mon Sep 17 00:00:00 2001 From: Paul Chubatyy Date: Tue, 28 Aug 2012 11:54:39 +0300 Subject: [PATCH 3/3] Changed the file mode back. --- lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php | 0 .../Tests/DBAL/Query/Expression/ExpressionBuilderTest.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php mode change 100755 => 100644 tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php diff --git a/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php b/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php old mode 100755 new mode 100644 diff --git a/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php old mode 100755 new mode 100644