Commit 3965d4f5 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge pull request #192 from Xobb/master

ExpressionBuilder in and notIn methods
parents bb88ba71 f812cc8c
......@@ -249,6 +249,32 @@ class ExpressionBuilder
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.
*
......
......@@ -198,4 +198,14 @@ class ExpressionBuilderTest extends \Doctrine\Tests\DbalTestCase
{
$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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment