From 62755cc647a0872d41b83d00ab2d5b888fc78fa0 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 20 Mar 2011 12:19:01 +0100 Subject: [PATCH] [DDC-1070] Fix in AbstractQuery::iterate() method not respecting hydrator and parameters. --- lib/Doctrine/ORM/AbstractQuery.php | 14 ++++++-- .../Tests/ORM/Functional/QueryTest.php | 33 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 6c8d0e5ff..bdad77973 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -501,10 +501,20 @@ abstract class AbstractQuery * @param integer $hydrationMode The hydration mode to use. * @return IterableResult */ - public function iterate(array $params = array(), $hydrationMode = self::HYDRATE_OBJECT) + public function iterate(array $params = array(), $hydrationMode = null) { + if ($hydrationMode !== null) { + $this->setHydrationMode($hydrationMode); + } + + if ($params) { + $this->setParameters($params); + } + + $stmt = $this->_doExecute(); + return $this->_em->newHydrator($this->_hydrationMode)->iterate( - $this->_doExecute($params, $hydrationMode), $this->_resultSetMapping, $this->_hints + $stmt, $this->_resultSetMapping, $this->_hints ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php index c4a0beda0..66785898e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php @@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\CMS\CmsUser, Doctrine\Tests\Models\CMS\CmsArticle; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Query; require_once __DIR__ . '/../../TestInit.php'; @@ -136,6 +137,38 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $users = $q->getResult(); } + /** + * @group DDC-1070 + */ + public function testIterateResultAsArrayAndParams() + { + $article1 = new CmsArticle; + $article1->topic = "Doctrine 2"; + $article1->text = "This is an introduction to Doctrine 2."; + + $article2 = new CmsArticle; + $article2->topic = "Symfony 2"; + $article2->text = "This is an introduction to Symfony 2."; + + $this->_em->persist($article1); + $this->_em->persist($article2); + + $this->_em->flush(); + $this->_em->clear(); + + $query = $this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.topic = ?1"); + $articles = $query->iterate(array(1 => 'Doctrine 2'), Query::HYDRATE_ARRAY); + + $found = array(); + foreach ($articles AS $article) { + $found[] = $article; + } + $this->assertEquals(1, count($found)); + $this->assertEquals(array( + array(array('id' => 1, 'topic' => 'Doctrine 2', 'text' => 'This is an introduction to Doctrine 2.', 'version' => 1)) + ), $found); + } + public function testIterateResult_IterativelyBuildUpUnitOfWork() { $article1 = new CmsArticle;