From d20b136270cba0b61da91b7ebcfb319e55c8b042 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 14 Dec 2013 12:03:39 +0100 Subject: [PATCH] Adding tests to verify that dql aliases in criteria are correctly converted --- tests/Doctrine/Tests/ORM/QueryBuilderTest.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php index f3c45c9af..ca79b5899 100644 --- a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php @@ -456,6 +456,40 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $this->assertSame('value2', $qb->getParameter('field2')->getValue()); } + /** + * @group DDC-2844 + */ + public function testAddCriteriaWhereWithMultipleParametersWithSubpathsAndDifferentProperties() + { + $qb = $this->_em->createQueryBuilder(); + $criteria = new Criteria(); + $criteria->where($criteria->expr()->eq('alias1.field1', 'value1')); + $criteria->andWhere($criteria->expr()->gt('alias1.field2', 'value2')); + + $qb->addCriteria($criteria); + + $this->assertEquals('alias1.field1 = :alias1_field1 AND alias1.field2 > :alias1_field2', (string) $qb->getDQLPart('where')); + $this->assertSame('value1', $qb->getParameter('alias1_field1')->getValue()); + $this->assertSame('value2', $qb->getParameter('alias1_field2')->getValue()); + } + + /** + * @group DDC-2844 + */ + public function testAddCriteriaWhereWithMultipleParametersWithSubpathsAndSameProperty() + { + $qb = $this->_em->createQueryBuilder(); + $criteria = new Criteria(); + $criteria->where($criteria->expr()->eq('alias1.field1', 'value1')); + $criteria->andWhere($criteria->expr()->gt('alias1.field1', 'value2')); + + $qb->addCriteria($criteria); + + $this->assertEquals('alias1.field1 = :alias1_field1 AND alias1.field1 > :alias1_field1_1', (string) $qb->getDQLPart('where')); + $this->assertSame('value1', $qb->getParameter('alias1_field1')->getValue()); + $this->assertSame('value2', $qb->getParameter('alias1_field1_1')->getValue()); + } + public function testAddCriteriaOrder() { $qb = $this->_em->createQueryBuilder();