1
0
mirror of synced 2025-02-20 22:23:14 +03:00

Don't add empty expression to another one

This commit is contained in:
Jean-Guilhem Rouel 2013-03-08 16:33:47 +01:00 committed by Benjamin Eberlei
parent ce0dd1c4f4
commit 8b8d1a5aaa
2 changed files with 15 additions and 1 deletions

View File

@ -86,7 +86,7 @@ abstract class Base
*/
public function add($arg)
{
if ( $arg !== null || ($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);

View File

@ -414,4 +414,18 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
$select = new Expr\Select(array('foo', 'bar'));
$this->assertEquals(array('foo', 'bar'), $select->getParts());
}
public function testAddEmpty() {
$andExpr = $this->_expr->andx();
$andExpr->add($this->_expr->andx());
$this->assertEquals(0, $andExpr->count());
}
public function testAddNull() {
$andExpr = $this->_expr->andx();
$andExpr->add(null);
$this->assertEquals(0, $andExpr->count());
}
}