Added MEMBER OF and INSTANCE OF helpers to ExpressionBuilder
This commit is contained in:
parent
9b4ae6d556
commit
400f420925
@ -644,4 +644,32 @@ class Expr
|
|||||||
{
|
{
|
||||||
return new Expr\Func('TRIM', $x);
|
return new Expr\Func('TRIM', $x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of MEMBER OF function, with the given arguments.
|
||||||
|
*
|
||||||
|
* @param string $x Value to be checked
|
||||||
|
* @param string $y Value to be checked against
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function isMemberOf($x, $y)
|
||||||
|
{
|
||||||
|
return $x . ' MEMBER OF ' . $y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of INSTANCE OF function, with the given arguments.
|
||||||
|
*
|
||||||
|
* @param string $x Value to be checked
|
||||||
|
* @param string $y Value to be checked against
|
||||||
|
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function isInstanceOf($x, $y)
|
||||||
|
{
|
||||||
|
return $x . ' INSTANCE OF ' . $y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,11 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
{
|
{
|
||||||
private $_em;
|
private $_em;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Expr
|
||||||
|
*/
|
||||||
|
private $_expr;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->_em = $this->_getTestEntityManager();
|
$this->_em = $this->_getTestEntityManager();
|
||||||
@ -271,6 +276,14 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$this->assertEquals('u.id IS NOT NULL', (string) $this->_expr->isNotNull('u.id'));
|
$this->assertEquals('u.id IS NOT NULL', (string) $this->_expr->isNotNull('u.id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testIsInstanceOfExpr() {
|
||||||
|
$this->assertEquals('u INSTANCE OF Doctrine\Tests\Models\Company\CompanyEmployee', (string) $this->_expr->isInstanceOf('u', 'Doctrine\Tests\Models\Company\CompanyEmployee'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsMemberOfExpr() {
|
||||||
|
$this->assertEquals(':groupId MEMBER OF u.groups', (string) $this->_expr->isMemberOf(':groupId', 'u.groups'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testInExpr()
|
public function testInExpr()
|
||||||
{
|
{
|
||||||
$this->assertEquals('u.id IN(1, 2, 3)', (string) $this->_expr->in('u.id', array(1, 2, 3)));
|
$this->assertEquals('u.id IN(1, 2, 3)', (string) $this->_expr->in('u.id', array(1, 2, 3)));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user