From 0a9876b2e818f242c2498fd34aaba408c018cd5e Mon Sep 17 00:00:00 2001 From: romanb Date: Fri, 15 Jan 2010 13:33:42 +0000 Subject: [PATCH] [2.0][DDC-248] Fixed and some more unrelated tests. --- lib/Doctrine/ORM/Mapping/ClassMetadata.php | 20 +++++++++--- .../OneToManyBidirectionalAssociationTest.php | 32 ++++++++++++++++--- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadata.php b/lib/Doctrine/ORM/Mapping/ClassMetadata.php index b90976e65..0c2f9d09a 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadata.php @@ -358,13 +358,23 @@ class ClassMetadata extends ClassMetadataInfo { // Restore ReflectionClass and properties $this->reflClass = new \ReflectionClass($this->name); - foreach ($this->fieldNames as $field) { - $this->reflFields[$field] = $this->reflClass->getProperty($field); - $this->reflFields[$field]->setAccessible(true); + foreach ($this->fieldMappings as $field => $mapping) { + if (isset($mapping['inherited'])) { + $reflField = new \ReflectionProperty($mapping['inherited'], $field); + } else { + $reflField = $this->reflClass->getProperty($field); + } + $reflField->setAccessible(true); + $this->reflFields[$field] = $reflField; } foreach ($this->associationMappings as $field => $mapping) { - $this->reflFields[$field] = $this->reflClass->getProperty($field); - $this->reflFields[$field]->setAccessible(true); + if (isset($this->inheritedAssociationFields[$field])) { + $reflField = new \ReflectionProperty($this->inheritedAssociationFields[$field], $field); + } else { + $reflField = $this->reflClass->getProperty($field); + } + $reflField->setAccessible(true); + $this->reflFields[$field] = $reflField; } //$this->prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name)); diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php index b6d2dd1d9..c4bf28bd5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php @@ -87,15 +87,15 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona public function testLazyLoadsObjectsOnTheOwningSide() { $this->_createFixture(); - $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct'); - $metadata->getAssociationMapping('features')->fetchMode = AssociationMapping::FETCH_LAZY; $query = $this->_em->createQuery('select p from Doctrine\Tests\Models\ECommerce\ECommerceProduct p'); $result = $query->getResult(); $product = $result[0]; $features = $product->getFeatures(); + $this->assertFalse($features->isInitialized()); $this->assertTrue($features[0] instanceof ECommerceFeature); + $this->assertTrue($features->isInitialized()); $this->assertSame($product, $features[0]->getProduct()); $this->assertEquals('Model writing tutorial', $features[0]->getDescription()); $this->assertTrue($features[1] instanceof ECommerceFeature); @@ -106,15 +106,39 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona public function testLazyLoadsObjectsOnTheInverseSide() { $this->_createFixture(); - $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceFeature'); - $metadata->getAssociationMapping('product')->fetchMode = AssociationMapping::FETCH_LAZY; $query = $this->_em->createQuery('select f from Doctrine\Tests\Models\ECommerce\ECommerceFeature f'); $features = $query->getResult(); $product = $features[0]->getProduct(); + $this->assertTrue($product instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertTrue($product instanceof ECommerceProduct); + $this->assertFalse($product->__isInitialized__); + $this->assertSame('Doctrine Cookbook', $product->getName()); + $this->assertTrue($product->__isInitialized__); + } + + public function testLazyLoadsObjectsOnTheInverseSide2() + { + //$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger); + $this->_createFixture(); + + $query = $this->_em->createQuery('select f,p from Doctrine\Tests\Models\ECommerce\ECommerceFeature f join f.product p'); + $features = $query->getResult(); + + $product = $features[0]->getProduct(); + $this->assertFalse($product instanceof \Doctrine\ORM\Proxy\Proxy); $this->assertTrue($product instanceof ECommerceProduct); $this->assertSame('Doctrine Cookbook', $product->getName()); + + $this->assertFalse($product->getFeatures()->isInitialized()); + + // This would trigger lazy-load + //$this->assertEquals(2, $product->getFeatures()->count()); + //$this->assertTrue($product->getFeatures()->contains($features[0])); + //$this->assertTrue($product->getFeatures()->contains($features[1])); + + //$this->_em->getConnection()->getConfiguration()->setSqlLogger(null); } public function testJoinFromOwningSide()