From cba4e55ac47b0ed1e9b326fdf336752447346956 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Sun, 10 Jun 2012 23:05:21 +0200 Subject: [PATCH] Added more coverage tests. Required result confirmation. --- .../Tests/ORM/Functional/QueryTest.php | 72 ++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php index fd1e14703..8d32811c2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php @@ -5,7 +5,9 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\DBAL\Connection; - +use Doctrine\Tests\Models\CMS\CmsUser, + Doctrine\Tests\Models\CMS\CmsArticle, + Doctrine\Tests\Models\CMS\CmsPhonenumber; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query; use Doctrine\ORM\Query\Parameter; @@ -713,4 +715,72 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertInstanceOf('\Doctrine\ORM\NonUniqueResultException', $exc); } } + + public function testMultipleJoinComponentsUsingInnerJoin() + { + $userA = new CmsUser; + $userA->name = 'Benjamin'; + $userA->username = 'beberlei'; + $userA->status = 'developer'; + + $phonenumberA = new CmsPhonenumber; + $phonenumberA->phonenumber = '111111'; + $userA->addPhonenumber($phonenumberA); + + $userB = new CmsUser; + $userB->name = 'Alexander'; + $userB->username = 'asm89'; + $userB->status = 'developer'; + + $this->_em->persist($userA); + $this->_em->persist($userB); + $this->_em->flush(); + $this->_em->clear(); + + $query = $this->_em->createQuery(" + SELECT u, p + FROM Doctrine\Tests\Models\CMS\CmsUser u + INNER JOIN Doctrine\Tests\Models\CMS\CmsPhonenumber p WITH u = p.user + "); + $users = $query->execute(); + + $this->assertEquals(2, count($users)); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $users[1]); + } + + public function testMultipleJoinComponentsUsingLeftJoin() + { + $userA = new CmsUser; + $userA->name = 'Benjamin'; + $userA->username = 'beberlei'; + $userA->status = 'developer'; + + $phonenumberA = new CmsPhonenumber; + $phonenumberA->phonenumber = '111111'; + $userA->addPhonenumber($phonenumberA); + + $userB = new CmsUser; + $userB->name = 'Alexander'; + $userB->username = 'asm89'; + $userB->status = 'developer'; + + $this->_em->persist($userA); + $this->_em->persist($userB); + $this->_em->flush(); + $this->_em->clear(); + + $query = $this->_em->createQuery(" + SELECT u, p + FROM Doctrine\Tests\Models\CMS\CmsUser u + LEFT JOIN Doctrine\Tests\Models\CMS\CmsPhonenumber p WITH u = p.user + "); + $users = $query->execute(); + + $this->assertEquals(4, count($users)); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $users[1]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[2]); + $this->assertNull($users[3]); + } }