Extra test for indexBy identifier versus indexBy other fields
This commit is contained in:
parent
2879162015
commit
70427871ce
@ -17,6 +17,10 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
private $groupId;
|
||||
private $articleId;
|
||||
|
||||
private $groupname;
|
||||
private $topic;
|
||||
private $phonenumber;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->useModelSet('cms');
|
||||
@ -24,9 +28,11 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
|
||||
$class->associationMappings['groups']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY;
|
||||
$class->associationMappings['groups']['indexBy'] = 'id';
|
||||
$class->associationMappings['groups']['indexBy'] = 'name';
|
||||
$class->associationMappings['articles']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY;
|
||||
$class->associationMappings['articles']['indexBy'] = 'id';
|
||||
$class->associationMappings['articles']['indexBy'] = 'topic';
|
||||
$class->associationMappings['phonenumbers']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY;
|
||||
$class->associationMappings['phonenumbers']['indexBy'] = 'phonenumber';
|
||||
|
||||
$class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup');
|
||||
$class->associationMappings['users']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY;
|
||||
@ -41,9 +47,11 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
|
||||
$class->associationMappings['groups']['fetch'] = ClassMetadataInfo::FETCH_LAZY;
|
||||
$class->associationMappings['articles']['fetch'] = ClassMetadataInfo::FETCH_LAZY;
|
||||
$class->associationMappings['phonenumbers']['fetch'] = ClassMetadataInfo::FETCH_LAZY;
|
||||
|
||||
unset($class->associationMappings['groups']['indexBy']);
|
||||
unset($class->associationMappings['articles']['indexBy']);
|
||||
unset($class->associationMappings['phonenumbers']['indexBy']);
|
||||
|
||||
$class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup');
|
||||
$class->associationMappings['users']['fetch'] = ClassMetadataInfo::FETCH_LAZY;
|
||||
@ -517,6 +525,26 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertEquals($qc + 1, $this->getCurrentQueryCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1398
|
||||
*/
|
||||
public function testGetIndexByIdentifier()
|
||||
{
|
||||
$user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
|
||||
/* @var $user CmsUser */
|
||||
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
|
||||
$phonenumber = $user->phonenumbers->get($this->phonenumber);
|
||||
|
||||
$this->assertFalse($user->phonenumbers->isInitialized());
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
|
||||
$this->assertSame($phonenumber, $this->_em->find('Doctrine\Tests\Models\CMS\CmsPhonenumber', $this->phonenumber));
|
||||
|
||||
$article = $user->phonenumbers->get($this->phonenumber);
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Getting the same entity should not cause an extra query to be executed");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1398
|
||||
*/
|
||||
@ -527,14 +555,11 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
|
||||
$article = $user->articles->get($this->articleId);
|
||||
$article = $user->articles->get($this->topic);
|
||||
|
||||
$this->assertFalse($user->articles->isInitialized());
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
|
||||
$this->assertSame($article, $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId));
|
||||
|
||||
$article = $user->articles->get($this->articleId);
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Getting the same entity should not cause an extra query to be executed");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -547,14 +572,11 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
|
||||
$group = $user->groups->get($this->groupId);
|
||||
$group = $user->groups->get($this->groupname);
|
||||
|
||||
$this->assertFalse($user->groups->isInitialized());
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
|
||||
$this->assertSame($group, $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId));
|
||||
|
||||
$group = $user->groups->get($this->groupId);
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Getting the same entity should not cause an extra query to be executed");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -618,23 +640,36 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->_em->persist($group3);
|
||||
|
||||
$article1 = new \Doctrine\Tests\Models\CMS\CmsArticle();
|
||||
$article1->topic = "Test";
|
||||
$article1->text = "Test";
|
||||
$article1->topic = "Test1";
|
||||
$article1->text = "Test1";
|
||||
$article1->setAuthor($user1);
|
||||
|
||||
$article2 = new \Doctrine\Tests\Models\CMS\CmsArticle();
|
||||
$article2->topic = "Test";
|
||||
$article2->text = "Test";
|
||||
$article2->topic = "Test2";
|
||||
$article2->text = "Test2";
|
||||
$article2->setAuthor($user1);
|
||||
|
||||
$this->_em->persist($article1);
|
||||
$this->_em->persist($article2);
|
||||
|
||||
$phonenumber1 = new \Doctrine\Tests\Models\CMS\CmsPhonenumber();
|
||||
$phonenumber1->phonenumber = '12345';
|
||||
|
||||
$phonenumber2 = new \Doctrine\Tests\Models\CMS\CmsPhonenumber();
|
||||
$phonenumber2->phonenumber = '67890';
|
||||
|
||||
$this->_em->persist($phonenumber1);
|
||||
$this->_em->persist($phonenumber2);
|
||||
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$this->articleId = $article1->id;
|
||||
$this->userId = $user1->getId();
|
||||
$this->groupId = $group1->id;
|
||||
|
||||
$this->groupname = $group1->name;
|
||||
$this->topic = $article1->topic;
|
||||
$this->phonenumber = $phonenumber1->phonenumber;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user