From b3e7493278ce4915d7b741a4ea3cd390030b82bb Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Tue, 29 May 2012 14:25:54 -0400 Subject: [PATCH] Made setParameters()/excute()/iterate() BC compatible. --- lib/Doctrine/ORM/AbstractQuery.php | 20 +++++++++++-------- lib/Doctrine/ORM/Query.php | 4 ++-- .../ORM/Functional/HydrationCacheTest.php | 10 +++++++--- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index b0c07e129..94a76f641 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -180,12 +180,16 @@ abstract class AbstractQuery /** * Sets a collection of query parameters. * - * @param \Doctrine\Common\Collections\ArrayCollection $parameters + * @param \Doctrine\Common\Collections\ArrayCollection|array $parameters * * @return \Doctrine\ORM\AbstractQuery This query instance. */ - public function setParameters(ArrayCollection $parameters) + public function setParameters($parameters) { + if (is_array($parameters)) { + $parameters = new ArrayCollection($parameters); + } + $this->parameters = $parameters; return $this; @@ -659,17 +663,17 @@ abstract class AbstractQuery * Executes the query and returns an IterableResult that can be used to incrementally * iterate over the result. * - * @param \Doctrine\Common\Collections\ArrayCollection $parameters The query parameters. + * @param \Doctrine\Common\Collections\ArrayCollection|array $parameters The query parameters. * @param integer $hydrationMode The hydration mode to use. * @return \Doctrine\ORM\Internal\Hydration\IterableResult */ - public function iterate(ArrayCollection $parameters = null, $hydrationMode = null) + public function iterate($parameters = null, $hydrationMode = null) { if ($hydrationMode !== null) { $this->setHydrationMode($hydrationMode); } - if ($parameters) { + if ( ! empty($parameters)) { $this->setParameters($parameters); } @@ -683,17 +687,17 @@ abstract class AbstractQuery /** * Executes the query. * - * @param \Doctrine\Common\Collections\ArrayCollection $parameters Query parameters. + * @param \Doctrine\Common\Collections\ArrayCollection|array $parameters Query parameters. * @param integer $hydrationMode Processing mode to be used during the hydration process. * @return mixed */ - public function execute(ArrayCollection $parameters = null, $hydrationMode = null) + public function execute($parameters = null, $hydrationMode = null) { if ($hydrationMode !== null) { $this->setHydrationMode($hydrationMode); } - if ($parameters) { + if ( ! empty($parameters)) { $this->setParameters($parameters); } diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 1238a1f7c..5ff7f96eb 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -526,11 +526,11 @@ final class Query extends AbstractQuery * Executes the query and returns an IterableResult that can be used to incrementally * iterated over the result. * - * @param \Doctrine\Common\Collections\ArrayCollection $parameters The query parameters. + * @param \Doctrine\Common\Collections\ArrayCollection|array $parameters The query parameters. * @param integer $hydrationMode The hydration mode to use. * @return \Doctrine\ORM\Internal\Hydration\IterableResult */ - public function iterate(ArrayCollection $parameters = null, $hydrationMode = self::HYDRATE_OBJECT) + public function iterate($parameters = null, $hydrationMode = self::HYDRATE_OBJECT) { $this->setHint(self::HINT_INTERNAL_ITERATION, true); diff --git a/tests/Doctrine/Tests/ORM/Functional/HydrationCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/HydrationCacheTest.php index 897421164..821c5dff4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/HydrationCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/HydrationCacheTest.php @@ -14,6 +14,7 @@ class HydrationCacheTest extends OrmFunctionalTestCase public function setUp() { $this->useModelSet('cms'); + parent::setUp(); $user = new CmsUser; @@ -72,14 +73,17 @@ class HydrationCacheTest extends OrmFunctionalTestCase $user = new CmsUser(); $user->id = 1; - $dql = "SELECT u FROM Doctrine\Tests\Models\Cms\CmsUser u WHERE u.id = ?1"; + $dql = "SELECT u FROM Doctrine\Tests\Models\Cms\CmsUser u WHERE u.id = ?1"; $query = $this->_em->createQuery($dql) - ->setParameter(1, $user) - ->setHydrationCacheProfile(new QueryCacheProfile(null, null, $cache)); + ->setParameter(1, $user) + ->setHydrationCacheProfile(new QueryCacheProfile(null, null, $cache)); $query->getResult(); + $c = $this->getCurrentQueryCount(); + $query->getResult(); + $this->assertEquals($c, $this->getCurrentQueryCount(), "Should not execute query. Its cached!"); } }