Skip to content

Commit

Permalink
Handle Empty Array
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Mar 20, 2020
1 parent e04a795 commit 800425c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Doctrine/ORM/Query/Expr/Func.php
Expand Up @@ -19,6 +19,8 @@

namespace Doctrine\ORM\Query\Expr;

use function count;

/**
* Expression class for generating DQL functions.
*
Expand Down Expand Up @@ -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) . ')';
}
}
10 changes: 10 additions & 0 deletions tests/Doctrine/Tests/ORM/Query/ExprTest.php
Expand Up @@ -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]));
Expand All @@ -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();
Expand Down

0 comments on commit 800425c

Please sign in to comment.