diff --git a/lib/Doctrine/ORM/Query/Expr.php b/lib/Doctrine/ORM/Query/Expr.php index a420b67b0..246f92717 100644 --- a/lib/Doctrine/ORM/Query/Expr.php +++ b/lib/Doctrine/ORM/Query/Expr.php @@ -443,6 +443,28 @@ class Expr return new Expr\Func($x . ' NOT IN', (array) $y); } + /** + * Creates an IS NULL expression with the given arguments. + * + * @param string $x Field in string format to be restricted by IS NULL + * @return string + */ + public function isNull($x) + { + return $x . ' IS NULL'; + } + + /** + * Creates an IS NOT NULL expression with the given arguments. + * + * @param string $x Field in string format to be restricted by IS NOT NULL + * @return string + */ + public function isNotNull($x) + { + return $x . ' IS NOT NULL'; + } + /** * Creates a LIKE() comparison expression with the given arguments. * diff --git a/tests/Doctrine/Tests/ORM/Query/ExprTest.php b/tests/Doctrine/Tests/ORM/Query/ExprTest.php index fffcf8afd..786eb1f0c 100644 --- a/tests/Doctrine/Tests/ORM/Query/ExprTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ExprTest.php @@ -256,6 +256,16 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('TRIM(u.id)', (string) $this->_expr->trim('u.id')); } + public function testIsNullExpr() + { + $this->assertEquals('u.id IS NULL', (string) $this->_expr->isNull('u.id')); + } + + public function testIsNotNullExpr() + { + $this->assertEquals('u.id IS NOT NULL', (string) $this->_expr->isNotNull('u.id')); + } + public function testInExpr() { $this->assertEquals('u.id IN(1, 2, 3)', (string) $this->_expr->in('u.id', array(1, 2, 3)));