diff --git a/lib/Doctrine/ORM/Query/Expr/Func.php b/lib/Doctrine/ORM/Query/Expr/Func.php index b4ed07cd3b2..644458cddd8 100644 --- a/lib/Doctrine/ORM/Query/Expr/Func.php +++ b/lib/Doctrine/ORM/Query/Expr/Func.php @@ -19,6 +19,8 @@ namespace Doctrine\ORM\Query\Expr; +use function count; + /** * Expression class for generating DQL functions. * @@ -73,6 +75,10 @@ public function getArguments() */ public function __toString() { + if (count($this->arguments) === 0) { + return $this->name . '(NULL)'; + } + return $this->name . '(' . implode(', ', $this->arguments) . ')'; } } diff --git a/tests/Doctrine/Tests/ORM/Query/ExprTest.php b/tests/Doctrine/Tests/ORM/Query/ExprTest.php index 37a4b70a657..69a999e302b 100644 --- a/tests/Doctrine/Tests/ORM/Query/ExprTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ExprTest.php @@ -282,6 +282,11 @@ public function testInLiteralExpr() $this->assertEquals("u.type IN('foo', 'bar')", (string) $this->_expr->in('u.type', ['foo', 'bar'])); } + public function testInExprForEmptyArray() + { + self::assertEquals('u.id IN(NULL)', (string) $this->_expr->in('u.id', [])); + } + public function testNotInExpr() { $this->assertEquals('u.id NOT IN(1, 2, 3)', (string) $this->_expr->notIn('u.id', [1, 2, 3])); @@ -292,6 +297,11 @@ public function testNotInLiteralExpr() $this->assertEquals("u.type NOT IN('foo', 'bar')", (string) $this->_expr->notIn('u.type', ['foo', 'bar'])); } + public function testNotInExprForEmptyArray() + { + self::assertEquals('u.id NOT IN(NULL)', (string) $this->_expr->notIn('u.id', [])); + } + public function testAndxOrxExpr() { $andExpr = $this->_expr->andX();