Unverified Commit cee81d54 authored by Grzegorz Kielak's avatar Grzegorz Kielak Committed by Marco Pivetta

Fix CompositeExpression add method optimization

parent 015f47af
......@@ -91,10 +91,16 @@ class CompositeExpression implements \Countable
*/
public function add($part)
{
if ( ! empty($part) || ($part instanceof self && $part->count() > 0)) {
$this->parts[] = $part;
if (empty($part)) {
return $this;
}
if ($part instanceof self && 0 === count($part)) {
return $this;
}
$this->parts[] = $part;
return $this;
}
......
......@@ -20,6 +20,29 @@ class CompositeExpressionTest extends \Doctrine\Tests\DbalTestCase
$this->assertEquals(2, count($expr));
}
public function testAdd()
{
$expr = new CompositeExpression(CompositeExpression::TYPE_OR, array('u.group_id = 1'));
$this->assertCount(1, $expr);
$expr->add(new CompositeExpression(CompositeExpression::TYPE_AND, array()));
$this->assertCount(1, $expr);
$expr->add(new CompositeExpression(CompositeExpression::TYPE_OR, array('u.user_id = 1')));
$this->assertCount(2, $expr);
$expr->add(null);
$this->assertCount(2, $expr);
$expr->add('u.user_id = 1');
$this->assertCount(3, $expr);
}
/**
* @dataProvider provideDataForConvertToString
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment