1
0
mirror of synced 2025-01-17 22:11:41 +03:00

Merge pull request #404 from Ocramius/DDC-1933

DDC-1933 - Fixing cloning of QueryBuilder and adding related tests
This commit is contained in:
Guilherme Blanco 2012-07-22 22:01:35 -07:00
commit 98c4833afc
2 changed files with 26 additions and 1 deletions

View File

@ -429,7 +429,7 @@ class QueryBuilder
*
* @param mixed $key The key (index or name) of the bound parameter.
*
* @return mixed The value of the bound parameter.
* @return Query\Parameter|null The value of the bound parameter.
*/
public function getParameter($key)
{
@ -1169,5 +1169,13 @@ class QueryBuilder
$this->_dqlParts[$part] = clone $elements;
}
}
$parameters = array();
foreach ($this->parameters as $parameter) {
$parameters[] = clone $parameter;
}
$this->parameters = new ArrayCollection($parameters);
}
}

View File

@ -664,6 +664,23 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals(2, $expr->count(), "Modifying the second query should affect the first one.");
}
/**
* @group DDC-1933
*/
public function testParametersAreCloned()
{
$originalQb = new QueryBuilder($this->_em);
$originalQb->setParameter('parameter1', 'value1');
$copy = clone $originalQb;
$copy->setParameter('parameter2', 'value2');
$this->assertCount(1, $originalQb->getParameters());
$this->assertSame('value1', $copy->getParameter('parameter1')->getValue());
$this->assertSame('value2', $copy->getParameter('parameter2')->getValue());
}
public function testGetRootAlias()
{
$qb = $this->_em->createQueryBuilder()