From dd7be5b13a6384b018d4f99549146141b2975ba4 Mon Sep 17 00:00:00 2001 From: "Roman S. Borschel" Date: Mon, 9 Aug 2010 22:27:34 +0200 Subject: [PATCH] Improving API and docblocks. Removing superfluous tests. --- lib/Doctrine/ORM/PersistentCollection.php | 2 +- lib/Doctrine/ORM/UnitOfWork.php | 15 ++++--- tests/Doctrine/Tests/ORM/AllTests.php | 1 - .../Tests/ORM/Associations/AllTests.php | 30 -------------- .../ORM/Associations/OneToOneMappingTest.php | 41 ------------------- .../Tests/ORM/PersistentCollectionTest.php | 20 +-------- 6 files changed, 9 insertions(+), 100 deletions(-) delete mode 100644 tests/Doctrine/Tests/ORM/Associations/AllTests.php delete mode 100644 tests/Doctrine/Tests/ORM/Associations/OneToOneMappingTest.php diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 0b7632605..34437d570 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -204,7 +204,7 @@ final class PersistentCollection implements Collection $newObjects = $this->coll->toArray(); } $this->coll->clear(); - $this->em->getUnitOfWork()->loadCollection($this->association, $this->owner, $this); + $this->em->getUnitOfWork()->loadCollection($this); $this->takeSnapshot(); // Reattach NEW objects added through add(), if any. if (isset($newObjects)) { diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 3700ac056..946197761 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1940,7 +1940,7 @@ class UnitOfWork implements PropertyChangedListener if ($assoc['fetch'] == ClassMetadata::FETCH_LAZY) { $pColl->setInitialized(false); } else { - $this->loadCollection($assoc, $entity, $pColl); + $this->loadCollection($pColl); } $this->originalEntityData[$oid][$field] = $pColl; } @@ -1960,23 +1960,22 @@ class UnitOfWork implements PropertyChangedListener } /** - * Initializes (loads) an associated collection of an entity. + * Initializes (loads) an uninitialized persistent collection of an entity. * - * @param array $assoc The association mapping. - * @param object $sourceEntity The entity that "owns" the collection. - * @param PeristentCollection $targetCollection The collection to initialize. + * @param PeristentCollection $collection The collection to initialize. * @todo Maybe later move to EntityManager#initialize($proxyOrCollection). See DDC-733. */ - public function loadCollection(array $assoc, $sourceEntity, $targetCollection) + public function loadCollection(PersistentCollection $collection) { + $assoc = $collection->getMapping(); switch ($assoc['type']) { case ClassMetadata::ONE_TO_MANY: $this->getEntityPersister($assoc['targetEntity'])->loadOneToManyCollection( - $assoc, $sourceEntity, $targetCollection); + $assoc, $collection->getOwner(), $collection); break; case ClassMetadata::MANY_TO_MANY: $this->getEntityPersister($assoc['targetEntity'])->loadManyToManyCollection( - $assoc, $sourceEntity, $targetCollection); + $assoc, $collection->getOwner(), $collection); break; } } diff --git a/tests/Doctrine/Tests/ORM/AllTests.php b/tests/Doctrine/Tests/ORM/AllTests.php index bd57ee892..fd7c25d7f 100644 --- a/tests/Doctrine/Tests/ORM/AllTests.php +++ b/tests/Doctrine/Tests/ORM/AllTests.php @@ -26,7 +26,6 @@ class AllTests $suite->addTest(Query\AllTests::suite()); $suite->addTest(Hydration\AllTests::suite()); $suite->addTest(Entity\AllTests::suite()); - //$suite->addTest(Associations\AllTests::suite()); $suite->addTest(Mapping\AllTests::suite()); $suite->addTest(Functional\AllTests::suite()); $suite->addTest(Id\AllTests::suite()); diff --git a/tests/Doctrine/Tests/ORM/Associations/AllTests.php b/tests/Doctrine/Tests/ORM/Associations/AllTests.php deleted file mode 100644 index 9f443976d..000000000 --- a/tests/Doctrine/Tests/ORM/Associations/AllTests.php +++ /dev/null @@ -1,30 +0,0 @@ -addTestSuite('Doctrine\Tests\ORM\Associations\OneToOneMappingTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Associations_AllTests::main') { - AllTests::main(); -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Associations/OneToOneMappingTest.php b/tests/Doctrine/Tests/ORM/Associations/OneToOneMappingTest.php deleted file mode 100644 index 2f6930757..000000000 --- a/tests/Doctrine/Tests/ORM/Associations/OneToOneMappingTest.php +++ /dev/null @@ -1,41 +0,0 @@ - ClassMetadata::ONE_TO_ONE, - 'fieldName' => 'address', - 'targetEntity' => 'Address', - 'joinColumns' => array(array('name' => 'address_id', 'referencedColumnName' => 'id')), - 'sourceEntity' => 'Person', // This is normally filled by ClassMetadata - ); - - $this->assertEquals(array('address_id' => 'id'), $oneToOneMapping->sourceToTargetKeyColumns); - $this->assertEquals(array('id' => 'address_id'), $oneToOneMapping->targetToSourceKeyColumns); - $this->assertEquals('Address', $oneToOneMapping->targetEntityName); - $this->assertEquals('Person', $oneToOneMapping->sourceEntityName); - $this->assertEquals('address', $oneToOneMapping->sourceFieldName); - $this->assertTrue($oneToOneMapping->isOwningSide); - - $oneToOneMapping = array( - 'type' => ClassMetadata::ONE_TO_ONE, - 'fieldName' => 'person', - 'sourceEntity' => 'Address', - 'targetEntity' => 'Person', - 'mappedBy' => 'address' - ); - - $this->assertEquals('address', $oneToOneMapping->mappedBy); - $this->assertEquals('Address', $oneToOneMapping->sourceEntityName); - $this->assertEquals('Person', $oneToOneMapping->targetEntityName); - $this->assertTrue( ! $oneToOneMapping->isOwningSide); - } -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index b3f20e99b..47eeb8b9a 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -32,24 +32,6 @@ class PersistentCollectionTest extends \Doctrine\Tests\OrmTestCase $class = $this->_emMock->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct'); $collection = new PersistentCollection($this->_emMock, $class, new ArrayCollection); $collection->setInitialized(false); - } - - public function testQueriesAssociationToLoadItself() - { - $this->markTestSkipped('Refactor!'); - - $class = $this->_emMock->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct'); - $collection = new PersistentCollection($this->_emMock, $class, new ArrayCollection); - $collection->setInitialized(false); - - $association = $this->getMock('Doctrine\ORM\Mapping\OneToManyMapping', array('load'), array(), '', false, false, false); - $association->targetEntityName = 'Doctrine\Tests\Models\ECommerce\ECommerceFeature'; - $product = new ECommerceProduct(); - $association->expects($this->once()) - ->method('load') - ->with($product, $this->isInstanceOf($collection), $this->isInstanceOf($this->_emMock)); - $collection->setOwner($product, $association); - - count($collection); + $this->assertFalse($collection->isInitialized()); } }