From 05568fa25922b886cdc34098c6ffbf1d9a120a04 Mon Sep 17 00:00:00 2001 From: guilhermeblanco Date: Sun, 6 Sep 2009 13:55:01 +0000 Subject: [PATCH] [2.0] Added coverage to expected behavior of IdentityMap --- .../StandardEntityPersisterTest.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php index 88b4a9098..2834173f8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php @@ -83,5 +83,37 @@ class StandardEntityPersisterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertTrue($feature === $f2); } } + + // Now we test how Hydrator affects IdentityMap + $f3 = new ECommerceFeature(); + $f3->setDescription('XVID'); + $p->addfeature($f3); + + $q = $this->_em->createQuery( + 'SELECT p, f + FROM Doctrine\Tests\Models\ECommerce\ECommerceProduct p + JOIN p.features f' + ); + + $res = $q->getResult(); + + // $p is our in-memory object... it should still contain the + // not yet managed Feature (it can't get lost) + $this->assertEquals(3, count($p->getFeatures())); + + // Now we persist the Feature #3 + $this->_em->persist($p); + $this->_em->flush(); + + $q = $this->_em->createQuery( + 'SELECT p, f + FROM Doctrine\Tests\Models\ECommerce\ECommerceProduct p + JOIN p.features f' + ); + + $res = $q->getResult(); + + // Persisted Product now must have 3 Feature items + $this->assertEquals(3, count($res[0]->getFeatures())); } }