Skip to content

Commit

Permalink
DDC-1211 - Fix bug with empty numeric literal
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Jun 19, 2011
1 parent d2eea18 commit cfe36f9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Query/Expr/Base.php
Expand Up @@ -55,7 +55,7 @@ public function addMultiple($args = array())

public function add($arg)
{
if ( ! empty($arg) || ($arg instanceof self && $arg->count() > 0)) {
if ( $arg !== null || ($arg instanceof self && $arg->count() > 0)) {
// If we decide to keep Expr\Base instances, we can use this check
if ( ! is_string($arg)) {
$class = get_class($arg);
Expand Down
28 changes: 28 additions & 0 deletions tests/Doctrine/Tests/ORM/QueryBuilderTest.php
Expand Up @@ -589,4 +589,32 @@ public function testDeepClone()

$this->assertEquals(2, $expr->count(), "Modifying the second query should affect the first one.");
}

/**
* @group DDC-1211
*/
public function testEmptyStringLiteral()
{
$expr = $this->_em->getExpressionBuilder();
$qb = $this->_em->createQueryBuilder()
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where($expr->eq('u.username', $expr->literal("")));

$this->assertEquals("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = ''", $qb->getDQL());
}

/**
* @group DDC-1211
*/
public function testEmptyNumericLiteral()
{
$expr = $this->_em->getExpressionBuilder();
$qb = $this->_em->createQueryBuilder()
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where($expr->eq('u.username', $expr->literal(0)));

$this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 0', $qb->getDQL());
}
}

0 comments on commit cfe36f9

Please sign in to comment.