From df8626b9498310248b265c9a0adec3023d01a886 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Sat, 24 Mar 2012 22:50:54 -0300 Subject: [PATCH] Fix DDC-1697 --- lib/Doctrine/ORM/AbstractQuery.php | 6 +++--- tests/Doctrine/Tests/ORM/Query/QueryTest.php | 21 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index fbb8b422f..4ada9160e 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -229,9 +229,9 @@ abstract class AbstractQuery { switch (true) { case is_array($value): - for ($i = 0, $l = count($value); $i < $l; $i++) { - $paramValue = $this->processParameterValue($value[$i]); - $value[$i] = is_array($paramValue) ? $paramValue[key($paramValue)] : $paramValue; + foreach ($value as $key => $paramValue) { + $paramValue = $this->processParameterValue($paramValue); + $value[$key] = is_array($paramValue) ? $paramValue[key($paramValue)] : $paramValue; } return $value; diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index f975af3ec..24267c5c5 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -125,4 +125,25 @@ class QueryTest extends \Doctrine\Tests\OrmTestCase $q = $this->_em->createQuery("SELECT DISTINCT u from Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a"); $q->iterate(); } + + /** + * @group DDC-1697 + */ + public function testKeyValueParameters() + { + $cities = array( + 0 => "Paris", + 3 => "Canne", + 9 => "St Julien" + ); + + $query = $this->_em + ->createQuery("SELECT a FROM Doctrine\Tests\Models\CMS\CmsAddress a WHERE a.city IN (:cities)") + ->setParameter('cities', $cities); + + $parameters = $query->getParameters(); + + $this->assertArrayHasKey('cities', $parameters); + $this->assertEquals($cities, $parameters['cities']); + } }