From 0b5c694a7e1ed717954b3aac986e05da374e1713 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 30 Aug 2010 20:30:11 +0200 Subject: [PATCH] DDC-778 - Fix AbstractQuery::__clone implementation that was wrongly implemented in DDC-770. Added more tests. --- lib/Doctrine/ORM/AbstractQuery.php | 4 +++- lib/Doctrine/ORM/Query.php | 11 +++++++++++ tests/Doctrine/Tests/ORM/Query/QueryTest.php | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 21974b792..e578a7e70 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -583,6 +583,8 @@ abstract class AbstractQuery */ public function __clone() { - $this->free(); + $this->_params = array(); + $this->_paramTypes = array(); + $this->_hints = array(); } } diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 4c755d0f4..f8338267b 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -544,4 +544,15 @@ final class Query extends AbstractQuery '&hydrationMode='.$this->_hydrationMode.'DOCTRINE_QUERY_CACHE_SALT' ); } + + /** + * Cleanup Query resource when clone is called. + * + * @return void + */ + public function __clone() + { + parent::__clone(); + $this->_state = self::STATE_DIRTY; + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index f606f0900..514c9d81c 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -44,4 +44,19 @@ class QueryTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals(array(), $query->getParameters()); } + + public function testClone() + { + $dql = "select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1"; + + $query = $this->_em->createQuery($dql); + $query->setParameter(2, 84, \PDO::PARAM_INT); + $query->setHint('foo', 'bar'); + + $cloned = clone $query; + + $this->assertEquals($dql, $cloned->getDql()); + $this->assertEquals(array(), $cloned->getParameters()); + $this->assertFalse($cloned->getHint('foo')); + } } \ No newline at end of file