1
0
mirror of synced 2025-01-18 06:21:40 +03:00

DDC-1933 - Fixing cloning of QueryBuilder and adding related tests

This commit is contained in:
Marco Pivetta 2012-07-20 01:17:45 +02:00
parent 93cef61270
commit fb3c6f0e8f
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. * @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) public function getParameter($key)
{ {
@ -1169,5 +1169,13 @@ class QueryBuilder
$this->_dqlParts[$part] = clone $elements; $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."); $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() public function testGetRootAlias()
{ {
$qb = $this->_em->createQueryBuilder() $qb = $this->_em->createQueryBuilder()