3 namespace Doctrine\Tests\ORM\Functional\Ticket;
5 use Doctrine\ORM\Mapping\ClassMetadataInfo;
7 require_once __DIR__ . '/../../../TestInit.php';
12 class DDC1301Test extends \Doctrine\Tests\OrmFunctionalTestCase
16 public function setUp()
18 $this->useModelSet('legacy');
21 $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\Legacy\LegacyUser');
22 $class->associationMappings['_articles']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY;
23 $class->associationMappings['_references']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY;
24 $class->associationMappings['_cars']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY;
29 public function tearDown()
33 $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\Legacy\LegacyUser');
34 $class->associationMappings['_articles']['fetch'] = ClassMetadataInfo::FETCH_LAZY;
35 $class->associationMappings['_references']['fetch'] = ClassMetadataInfo::FETCH_LAZY;
36 $class->associationMappings['_cars']['fetch'] = ClassMetadataInfo::FETCH_LAZY;
39 public function testCountNotInitializesLegacyCollection()
41 $user = $this->_em->find('Doctrine\Tests\Models\Legacy\LegacyUser', $this->userId);
42 $queryCount = $this->getCurrentQueryCount();
44 $this->assertFalse($user->_articles->isInitialized());
45 $this->assertEquals(2, count($user->_articles));
46 $this->assertFalse($user->_articles->isInitialized());
48 foreach ($user->_articles AS $article) { }
50 $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount(), "Expecting two queries to be fired for count, then iteration.");
53 public function testCountNotInitializesLegacyCollectionWithForeignIdentifier()
55 $user = $this->_em->find('Doctrine\Tests\Models\Legacy\LegacyUser', $this->userId);
56 $queryCount = $this->getCurrentQueryCount();
58 $this->assertFalse($user->_references->isInitialized());
59 $this->assertEquals(2, count($user->_references));
60 $this->assertFalse($user->_references->isInitialized());
62 foreach ($user->_references AS $reference) { }
64 $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount(), "Expecting two queries to be fired for count, then iteration.");
67 public function testCountNotInitializesLegacyManyToManyCollection()
69 $user = $this->_em->find('Doctrine\Tests\Models\Legacy\LegacyUser', $this->userId);
70 $queryCount = $this->getCurrentQueryCount();
72 $this->assertFalse($user->_cars->isInitialized());
73 $this->assertEquals(3, count($user->_cars));
74 $this->assertFalse($user->_cars->isInitialized());
76 foreach ($user->_cars AS $reference) { }
78 $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount(), "Expecting two queries to be fired for count, then iteration.");
81 public function loadFixture()
83 $user1 = new \Doctrine\Tests\Models\Legacy\LegacyUser();
84 $user1->_username = "beberlei";
85 $user1->_name = "Benjamin";
86 $user1->_status = "active";
88 $user2 = new \Doctrine\Tests\Models\Legacy\LegacyUser();
89 $user2->_username = "jwage";
90 $user2->_name = "Jonathan";
91 $user2->_status = "active";
93 $user3 = new \Doctrine\Tests\Models\Legacy\LegacyUser();
94 $user3->_username = "romanb";
95 $user3->_name = "Roman";
96 $user3->_status = "active";
98 $this->_em->persist($user1);
99 $this->_em->persist($user2);
100 $this->_em->persist($user3);
102 $article1 = new \Doctrine\Tests\Models\Legacy\LegacyArticle();
103 $article1->_topic = "Test";
104 $article1->_text = "Test";
105 $article1->setAuthor($user1);
107 $article2 = new \Doctrine\Tests\Models\Legacy\LegacyArticle();
108 $article2->_topic = "Test";
109 $article2->_text = "Test";
110 $article2->setAuthor($user1);
112 $this->_em->persist($article1);
113 $this->_em->persist($article2);
115 $car1 = new \Doctrine\Tests\Models\Legacy\LegacyCar();
116 $car1->_description = "Test1";
118 $car2 = new \Doctrine\Tests\Models\Legacy\LegacyCar();
119 $car2->_description = "Test2";
121 $car3 = new \Doctrine\Tests\Models\Legacy\LegacyCar();
122 $car3->_description = "Test3";
124 $user1->addCar($car1);
125 $user1->addCar($car2);
126 $user1->addCar($car3);
128 $user2->addCar($car1);
129 $user3->addCar($car1);
131 $this->_em->persist($car1);
132 $this->_em->persist($car2);
133 $this->_em->persist($car3);
137 $detail1 = new \Doctrine\Tests\Models\Legacy\LegacyUserReference($user1, $user2, "foo");
138 $detail2 = new \Doctrine\Tests\Models\Legacy\LegacyUserReference($user1, $user3, "bar");
140 $this->_em->persist($detail1);
141 $this->_em->persist($detail2);
146 $this->userId = $user1->getId();