-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #549 from FabioBatSilva/DDC-1376
[DDC-1376] Support for order by association when using findBy
- Loading branch information
Showing
2 changed files
with
106 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
namespace Doctrine\Tests\ORM\Functional; | ||
|
||
use Doctrine\Tests\Models\CMS\CmsUser; | ||
use Doctrine\Tests\Models\CMS\CmsEmail; | ||
use Doctrine\Tests\Models\CMS\CmsAddress; | ||
use Doctrine\Tests\Models\CMS\CmsPhonenumber; | ||
use Doctrine\Common\Collections\Criteria; | ||
|
@@ -89,6 +90,50 @@ public function loadAssociatedFixture() | |
return array($user->id, $address->id); | ||
} | ||
|
||
public function loadFixtureUserEmail() | ||
{ | ||
$user1 = new CmsUser(); | ||
$user2 = new CmsUser(); | ||
$user3 = new CmsUser(); | ||
|
||
$email1 = new CmsEmail(); | ||
$email2 = new CmsEmail(); | ||
$email3 = new CmsEmail(); | ||
|
||
$user1->name = 'Test 1'; | ||
$user1->username = 'test1'; | ||
$user1->status = 'active'; | ||
|
||
$user2->name = 'Test 2'; | ||
$user2->username = 'test2'; | ||
$user2->status = 'active'; | ||
|
||
$user3->name = 'Test 3'; | ||
$user3->username = 'test3'; | ||
$user3->status = 'active'; | ||
|
||
$email1->email = '[email protected]'; | ||
$email2->email = '[email protected]'; | ||
$email3->email = '[email protected]'; | ||
|
||
$user1->setEmail($email1); | ||
$user2->setEmail($email2); | ||
$user3->setEmail($email3); | ||
|
||
$this->_em->persist($user1); | ||
$this->_em->persist($user2); | ||
$this->_em->persist($user3); | ||
|
||
$this->_em->persist($email1); | ||
$this->_em->persist($email2); | ||
$this->_em->persist($email3); | ||
|
||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
|
||
return array($user1, $user2, $user3); | ||
} | ||
|
||
public function buildUser($name, $username, $status, $address) | ||
{ | ||
$user = new CmsUser(); | ||
|
@@ -476,6 +521,24 @@ public function testFindByOrderBy() | |
$this->assertSame($usersAsc[3], $usersDesc[0]); | ||
} | ||
|
||
/** | ||
* @group DDC-1376 | ||
*/ | ||
public function testFindByOrderByAssociation() | ||
{ | ||
$this->loadFixtureUserEmail(); | ||
|
||
$repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); | ||
$resultAsc = $repository->findBy(array(), array('email' => 'ASC')); | ||
$resultDesc = $repository->findBy(array(), array('email' => 'DESC')); | ||
|
||
$this->assertCount(3, $resultAsc); | ||
$this->assertCount(3, $resultDesc); | ||
|
||
$this->assertEquals($resultAsc[0]->getEmail()->getId(), $resultDesc[2]->getEmail()->getId()); | ||
$this->assertEquals($resultAsc[2]->getEmail()->getId(), $resultDesc[0]->getEmail()->getId()); | ||
} | ||
|
||
/** | ||
* @group DDC-1426 | ||
*/ | ||
|
@@ -538,7 +601,6 @@ public function testDefaultRepositoryClassName() | |
|
||
} | ||
|
||
|
||
/** | ||
* @group DDC-753 | ||
* @expectedException Doctrine\ORM\ORMException | ||
|
@@ -550,6 +612,18 @@ public function testSetDefaultRepositoryInvalidClassError() | |
$this->_em->getConfiguration()->setDefaultRepositoryClassName("Doctrine\Tests\Models\DDC753\DDC753InvalidRepository"); | ||
} | ||
|
||
/** | ||
* @group DDC-1376 | ||
* | ||
* @expectedException Doctrine\ORM\ORMException | ||
* @expectedExceptionMessage You cannot search for the association field 'Doctrine\Tests\Models\CMS\CmsUser#address', because it is the inverse side of an association. | ||
*/ | ||
public function testInvalidOrderByAsssociation() | ||
{ | ||
$this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') | ||
->findBy(array('status' => 'test'), array('address' => 'ASC')); | ||
} | ||
|
||
/** | ||
* @group DDC-1500 | ||
*/ | ||
|