Commit 1b35a53e authored by Guilherme Blanco's avatar Guilherme Blanco

Merge pull request #680 from hason/in

Enabled placeholders for "in" method in ExpressionBuilder
parents 040d49c1 cc0dfa85
......@@ -275,27 +275,27 @@ class ExpressionBuilder
/**
* Creates a IN () comparison expression with the given arguments.
*
* @param string $x The field in string format to be inspected by IN() comparison.
* @param array $y The array of values to be used by IN() comparison.
* @param string $x The field in string format to be inspected by IN() comparison.
* @param string|array $y The placeholder or the array of values to be used by IN() comparison.
*
* @return string
*/
public function in($x, array $y)
public function in($x, $y)
{
return $this->comparison($x, 'IN', '('.implode(', ', $y).')');
return $this->comparison($x, 'IN', '('.implode(', ', (array) $y).')');
}
/**
* Creates a NOT IN () comparison expression with the given arguments.
*
* @param string $x The field in string format to be inspected by NOT IN() comparison.
* @param array $y The array of values to be used by NOT IN() comparison.
* @param string $x The field in string format to be inspected by NOT IN() comparison.
* @param string|array $y The placeholder or the array of values to be used by NOT IN() comparison.
*
* @return string
*/
public function notIn($x, array $y)
public function notIn($x, $y)
{
return $this->comparison($x, 'NOT IN', '('.implode(', ', $y).')');
return $this->comparison($x, 'NOT IN', '('.implode(', ', (array) $y).')');
}
/**
......
......@@ -204,8 +204,18 @@ class ExpressionBuilderTest extends \Doctrine\Tests\DbalTestCase
$this->assertEquals('u.groups IN (1, 3, 4, 7)', $this->expr->in('u.groups', array(1,3,4,7)));
}
public function testInWithPlaceholder()
{
$this->assertEquals('u.groups IN (?)', $this->expr->in('u.groups', '?'));
}
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
public function testNotInWithPlaceholder()
{
$this->assertEquals('u.groups NOT IN (:values)', $this->expr->notIn('u.groups', ':values'));
}
}
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