1
0
mirror of synced 2025-02-20 06:03:15 +03:00

Improving API and docblocks. Removing superfluous tests.

This commit is contained in:
Roman S. Borschel 2010-08-09 22:27:34 +02:00
parent 4826739824
commit dd7be5b13a
6 changed files with 9 additions and 100 deletions

View File

@ -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)) {

View File

@ -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;
}
}

View File

@ -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());

View File

@ -1,30 +0,0 @@
<?php
namespace Doctrine\Tests\ORM\Associations;
if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'Orm_Associations_AllTests::main');
}
require_once __DIR__ . '/../../TestInit.php';
class AllTests
{
public static function main()
{
\PHPUnit_TextUI_TestRunner::run(self::suite());
}
public static function suite()
{
$suite = new \Doctrine\Tests\DoctrineTestSuite('Doctrine Orm Associations');
$suite->addTestSuite('Doctrine\Tests\ORM\Associations\OneToOneMappingTest');
return $suite;
}
}
if (PHPUnit_MAIN_METHOD == 'Orm_Associations_AllTests::main') {
AllTests::main();
}

View File

@ -1,41 +0,0 @@
<?php
namespace Doctrine\Tests\ORM\Associations;
require_once __DIR__ . '/../../TestInit.php';
use Doctrine\ORM\Mapping\ClassMetadata;
class OneToOneMappingTest extends \Doctrine\Tests\OrmTestCase
{
public function testCorrectOneToOneBidirectionalMapping()
{
$oneToOneMapping = array(
'type' => 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);
}
}

View File

@ -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());
}
}