diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 554e17d7e..9685b053f 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -376,35 +376,41 @@ class EntityManager } /** - * Saves the given entity, persisting it's state. + * Tells the EntityManager to make an instance managed and persistent. * - * @param object $object + * The entity will be entered into the database at or before transaction + * commit or as a result of the flush operation. + * + * @param object $object The instance to make managed and persistent. */ - public function save($object) + public function persist($object) { $this->_errorIfClosed(); - $this->_unitOfWork->save($object); + $this->_unitOfWork->persist($object); if ($this->_flushMode == self::FLUSHMODE_IMMEDIATE) { $this->flush(); } } /** - * Deletes the persistent state of the given entity. + * Removes an entity instance. * - * @param object $entity + * A removed entity will be removed from the database at or before transaction commit + * or as a result of the flush operation. + * + * @param object $entity The entity instance to remove. */ - public function delete($entity) + public function remove($entity) { $this->_errorIfClosed(); - $this->_unitOfWork->delete($entity); + $this->_unitOfWork->remove($entity); if ($this->_flushMode == self::FLUSHMODE_IMMEDIATE) { $this->flush(); } } /** - * Refreshes the persistent state of the entity from the database, + * Refreshes the persistent state of an entity from the database, * overriding any local changes that have not yet been persisted. * * @param object $entity @@ -417,7 +423,7 @@ class EntityManager } /** - * Detaches an entity from the EntityManager. Its lifecycle is no longer managed. + * Detaches an entity from the EntityManager. * * @param object $entity The entity to detach. * @return boolean @@ -476,7 +482,7 @@ class EntityManager } /** - * Checks if the instance is managed by the EntityManager. + * Determines whether an entity instance is managed in this EntityManager. * * @param object $entity * @return boolean TRUE if this EntityManager currently manages the given entity @@ -485,7 +491,7 @@ class EntityManager public function contains($entity) { return $this->_unitOfWork->isInIdentityMap($entity) && - ! $this->_unitOfWork->isRegisteredRemoved($entity); + ! $this->_unitOfWork->isScheduledForDelete($entity); } /** diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 4f8af76dc..927d81e65 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -199,7 +199,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection { //TODO: delete entity if shouldDeleteOrphans /*if ($this->_association->isOneToMany() && $this->_association->shouldDeleteOrphans()) { - $this->_em->delete($removed); + $this->_em->remove($removed); }*/ $removed = parent::remove($key); if ($removed) { @@ -377,7 +377,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection //TODO: If oneToMany() && shouldDeleteOrphan() delete entities /*if ($this->_association->isOneToMany() && $this->_association->shouldDeleteOrphans()) { foreach ($this->_data as $entity) { - $this->_em->delete($entity); + $this->_em->remove($entity); } }*/ parent::clear(); diff --git a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php index 974100689..4dc0c3c7d 100644 --- a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php @@ -351,7 +351,7 @@ class StandardEntityPersister // Special case: One-one self-referencing of the same class. if ($newVal !== null && $assocMapping->sourceEntityName == $assocMapping->targetEntityName) { $oid = spl_object_hash($newVal); - $isScheduledForInsert = $uow->isRegisteredNew($newVal); + $isScheduledForInsert = $uow->isScheduledForInsert($newVal); if (isset($this->_queuedInserts[$oid]) || $isScheduledForInsert) { // The associated entity $newVal is not yet persisted, so we must // set $newVal = null, in order to insert a null value and schedule an diff --git a/lib/Doctrine/ORM/Query/ResultSetMapping.php b/lib/Doctrine/ORM/Query/ResultSetMapping.php index c925e0dd9..4877bb50b 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMapping.php +++ b/lib/Doctrine/ORM/Query/ResultSetMapping.php @@ -166,7 +166,7 @@ class ResultSetMapping if ( ! $this->isMixed && $this->fieldMappings) { $this->isMixed = true; } - } + } /** * @return boolean diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index fdd51d593..38ff888a1 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -58,7 +58,7 @@ class UnitOfWork implements PropertyChangedListener const STATE_MANAGED = 1; /** - * An entity is new if it does not yet have an identifier/primary key + * An entity is new if it has just been instantiated * and is not (yet) managed by an EntityManager. */ const STATE_NEW = 2; @@ -66,7 +66,6 @@ class UnitOfWork implements PropertyChangedListener /** * A detached entity is an instance with a persistent identity that is not * (or no longer) associated with an EntityManager (and a UnitOfWork). - * This means it is no longer in the identity map. */ const STATE_DETACHED = 3; @@ -88,7 +87,7 @@ class UnitOfWork implements PropertyChangedListener private $_identityMap = array(); /** - * Map of all identifiers. Keys are object ids. + * Map of all identifiers. Keys are object ids (spl_object_hash). * * @var array */ @@ -96,15 +95,18 @@ class UnitOfWork implements PropertyChangedListener /** * Map of the original entity data of entities fetched from the database. - * Keys are object ids. This is used for calculating changesets at commit time. - * Note that PHPs "copy-on-write" behavior helps a lot with memory usage. + * Keys are object ids (spl_object_hash). This is used for calculating changesets + * at commit time. * * @var array + * @internal Note that PHPs "copy-on-write" behavior helps a lot with memory usage. + * A value will only really be copied if the value in the entity is modified + * by the user. */ private $_originalEntityData = array(); /** - * Map of data changes. Keys are object ids. + * Map of data changes. Keys are object ids (spl_object_hash). * Filled at the beginning of a commit of the UnitOfWork and cleaned at the end. * * @var array @@ -113,6 +115,7 @@ class UnitOfWork implements PropertyChangedListener /** * The states of entities in this UnitOfWork. + * Keys are object ids (spl_object_hash). * * @var array */ @@ -121,6 +124,9 @@ class UnitOfWork implements PropertyChangedListener /** * Map of entities that are scheduled for dirty checking at commit time. * This is only used if automatic dirty checking is disabled. + * Keys are object ids (spl_object_hash). + * + * @var array */ private $_scheduledForDirtyCheck = array(); @@ -164,7 +170,7 @@ class UnitOfWork implements PropertyChangedListener * * @var array */ - private $_collectionCreations = array(); + //private $_collectionCreations = array(); /** * All collection updates. @@ -355,26 +361,25 @@ class UnitOfWork implements PropertyChangedListener * If automatic dirty checking is disabled, only those changesets will be * computed that have been scheduled through scheduleForDirtyCheck(). */ - public function computeChangeSets(array $entities = null) + public function computeChangeSets() { - $entitySet = array(); - $newEntities = array(); - if ($entities !== null) { - foreach ($entities as $entity) { - $entitySet[get_class($entity)][] = $entity; + $entitySet = $this->_identityMap; + $entityInsertions = $this->_entityInsertions; + + // Compute changes for INSERTed entities first. This must always happen. + foreach ($entityInsertions as $entity) { + $class = $this->_em->getClassMetadata(get_class($entity)); + $this->_computeEntityChanges($class, $entity); + // Look for changes in associations of the entity + foreach ($class->associationMappings as $assoc) { + $val = $class->reflFields[$assoc->sourceFieldName]->getValue($entity); + if ($val !== null) { + $this->_computeAssociationChanges($assoc, $val); + } } - $newEntities = $entities; - } else { - $entitySet = $this->_identityMap; - $newEntities = $this->_entityInsertions; } - // Compute changes for NEW entities first. This must always happen. - foreach ($newEntities as $entity) { - $this->_computeEntityChanges($this->_em->getClassMetadata(get_class($entity)), $entity); - } - - // Compute changes for MANAGED entities. Change tracking policies take effect here. + // Compute changes for other MANAGED entities. Change tracking policies take effect here. foreach ($entitySet as $className => $entities) { $class = $this->_em->getClassMetadata($className); @@ -388,8 +393,9 @@ class UnitOfWork implements PropertyChangedListener $this->_scheduledForDirtyCheck[$className] : $entities; foreach ($entitiesToProcess as $entity) { - // Only MANAGED entities are processed here. - if ($this->getEntityState($entity) == self::STATE_MANAGED) { + // Only MANAGED entities that are NOT INSERTED are processed here. + $oid = spl_object_hash($entity); + if (isset($this->_entityStates[$oid]) && ! isset($entityInsertions[$oid])) { $this->_computeEntityChanges($class, $entity); // Look for changes in associations of the entity foreach ($class->associationMappings as $assoc) { @@ -454,7 +460,7 @@ class UnitOfWork implements PropertyChangedListener $assoc = $class->associationMappings[$name]; // Inject PersistentCollection $coll = new PersistentCollection($this->_em, $this->_em->getClassMetadata($assoc->targetEntityName), - $actualData[$name] ? $actualData[$name] : array()); + $actualData[$name] ? $actualData[$name] : array()); $coll->setOwner($entity, $assoc); $coll->setDirty( ! $coll->isEmpty()); $class->reflFields[$name]->setValue($entity, $coll); @@ -808,13 +814,12 @@ class UnitOfWork implements PropertyChangedListener } /** - * Registers a new entity. The entity will be scheduled for insertion. + * Schedules an entity for insertion into the database. * If the entity already has an identifier, it will be added to the identity map. * * @param object $entity - * @todo Rename to scheduleForInsert(). */ - public function registerNew($entity) + public function scheduleForInsert($entity) { $oid = spl_object_hash($entity); @@ -839,9 +844,8 @@ class UnitOfWork implements PropertyChangedListener * * @param object $entity * @return boolean - * @todo Rename to isScheduledForInsert(). */ - public function isRegisteredNew($entity) + public function isScheduledForInsert($entity) { return isset($this->_entityInsertions[spl_object_hash($entity)]); } @@ -850,9 +854,8 @@ class UnitOfWork implements PropertyChangedListener * Registers a dirty entity. * * @param object $entity - * @todo Rename to scheduleForUpdate(). */ - public function registerDirty($entity) + public function scheduleForUpdate($entity) { $oid = spl_object_hash($entity); if ( ! isset($this->_entityIdentifiers[$oid])) { @@ -887,19 +890,18 @@ class UnitOfWork implements PropertyChangedListener * * @param object $entity * @return boolean - * @todo Rename to isScheduledForUpdate(). */ - public function isRegisteredDirty($entity) + public function isScheduledForUpdate($entity) { return isset($this->_entityUpdates[spl_object_hash($entity)]); } /** * Registers a deleted entity. - * - * @todo Rename to scheduleForDelete(). + * + * @param object $entity */ - public function registerDeleted($entity) + public function scheduleForDelete($entity) { $oid = spl_object_hash($entity); if ( ! $this->isInIdentityMap($entity)) { @@ -928,9 +930,8 @@ class UnitOfWork implements PropertyChangedListener * * @param object $entity * @return boolean - * @todo Rename to isScheduledForDelete(). */ - public function isRegisteredRemoved($entity) + public function isScheduledForDelete($entity) { return isset($this->_entityDeletions[spl_object_hash($entity)]); } @@ -946,17 +947,17 @@ class UnitOfWork implements PropertyChangedListener $oid = spl_object_hash($entity); $this->removeFromIdentityMap($entity); unset($this->_entityInsertions[$oid], $this->_entityUpdates[$oid], - $this->_entityDeletions[$oid], $this->_entityIdentifiers[$oid], - $this->_entityStates[$oid]); + $this->_entityDeletions[$oid], $this->_entityIdentifiers[$oid], + $this->_entityStates[$oid]); } /** - * + * Checks whether an entity is scheduled for insertion, update or deletion. * * @param $entity - * @return unknown_type + * @return boolean */ - public function isEntityRegistered($entity) + public function isEntityScheduled($entity) { $oid = spl_object_hash($entity); return isset($this->_entityInsertions[$oid]) || @@ -1110,28 +1111,10 @@ class UnitOfWork implements PropertyChangedListener * * @param object $entity The entity to save. */ - public function save($entity) + public function persist($entity) { - $insertNow = array(); $visited = array(); - $this->_doSave($entity, $visited, $insertNow); - if ( ! empty($insertNow)) { - // We have no choice. This means that there are new entities - // with a post-insert ID generation strategy. - $this->computeChangeSets($insertNow); - $commitOrder = $this->_getCommitOrder($insertNow); - foreach ($commitOrder as $class) { - $this->_executeInserts($class); - } - // Extra updates that were requested by persisters. - if ($this->_extraUpdates) { - $this->_executeExtraUpdates(); - $this->_extraUpdates = array(); - } - // Remove them from _entityInsertions and _entityChangeSets - $this->_entityInsertions = array_diff_key($this->_entityInsertions, $insertNow); - $this->_entityChangeSets = array_diff_key($this->_entityChangeSets, $insertNow); - } + $this->_doPersist($entity, $visited); } /** @@ -1144,7 +1127,7 @@ class UnitOfWork implements PropertyChangedListener * @param array $insertNow The entities that must be immediately inserted because of * post-insert ID generation. */ - private function _doSave($entity, array &$visited, array &$insertNow) + private function _doPersist($entity, array &$visited) { $oid = spl_object_hash($entity); if (isset($visited[$oid])) { @@ -1170,11 +1153,8 @@ class UnitOfWork implements PropertyChangedListener } $idGen = $class->idGenerator; - if ($idGen->isPostInsertGenerator()) { - $insertNow[$oid] = $entity; - } else { + if ( ! $idGen->isPostInsertGenerator()) { $idValue = $idGen->generate($this->_em, $entity); - $this->_entityStates[$oid] = self::STATE_MANAGED; if ( ! $idGen instanceof \Doctrine\ORM\Id\Assigned) { $this->_entityIdentifiers[$oid] = array($idValue); $class->setIdentifierValues($entity, $idValue); @@ -1182,24 +1162,26 @@ class UnitOfWork implements PropertyChangedListener $this->_entityIdentifiers[$oid] = $idValue; } } - $this->registerNew($entity); + $this->_entityStates[$oid] = self::STATE_MANAGED; + + $this->scheduleForInsert($entity); break; case self::STATE_DETACHED: throw DoctrineException::updateMe("Behavior of save() for a detached entity " . "is not yet defined."); case self::STATE_DELETED: // Entity becomes managed again - if ($this->isRegisteredRemoved($entity)) { + if ($this->isScheduledForDelete($entity)) { unset($this->_entityDeletions[$oid]); } else { //FIXME: There's more to think of here... - $this->registerNew($entity); + $this->scheduleForInsert($entity); } break; default: throw DoctrineException::updateMe("Encountered invalid entity state."); } - $this->_cascadeSave($entity, $visited, $insertNow); + $this->_cascadePersist($entity, $visited); } /** @@ -1207,10 +1189,10 @@ class UnitOfWork implements PropertyChangedListener * * @param object $entity */ - public function delete($entity) + public function remove($entity) { $visited = array(); - $this->_doDelete($entity, $visited); + $this->_doRemove($entity, $visited); } /** @@ -1222,7 +1204,7 @@ class UnitOfWork implements PropertyChangedListener * @param object $entity The entity to delete. * @param array $visited The map of the already visited entities. */ - private function _doDelete($entity, array &$visited) + private function _doRemove($entity, array &$visited) { $oid = spl_object_hash($entity); if (isset($visited[$oid])) { @@ -1244,14 +1226,14 @@ class UnitOfWork implements PropertyChangedListener if ($this->_evm->hasListeners(Events::preDelete)) { $this->_evm->dispatchEvent(Events::preDelete, new LifecycleEventArgs($entity)); } - $this->registerDeleted($entity); + $this->scheduleForDelete($entity); break; case self::STATE_DETACHED: throw DoctrineException::updateMe("A detached entity can't be deleted."); default: throw DoctrineException::updateMe("Encountered invalid entity state."); } - $this->_cascadeDelete($entity, $visited); + $this->_cascadeRemove($entity, $visited); } /** @@ -1361,7 +1343,7 @@ class UnitOfWork implements PropertyChangedListener * @param array $visited * @param array $insertNow */ - private function _cascadeSave($entity, array &$visited, array &$insertNow) + private function _cascadePersist($entity, array &$visited) { $class = $this->_em->getClassMetadata(get_class($entity)); foreach ($class->associationMappings as $assocMapping) { @@ -1371,10 +1353,10 @@ class UnitOfWork implements PropertyChangedListener $relatedEntities = $class->reflFields[$assocMapping->sourceFieldName]->getValue($entity); if (($relatedEntities instanceof Collection || is_array($relatedEntities))) { foreach ($relatedEntities as $relatedEntity) { - $this->_doSave($relatedEntity, $visited, $insertNow); + $this->_doPersist($relatedEntity, $visited); } } else if ($relatedEntities !== null) { - $this->_doSave($relatedEntities, $visited, $insertNow); + $this->_doPersist($relatedEntities, $visited); } } } @@ -1385,7 +1367,7 @@ class UnitOfWork implements PropertyChangedListener * @param object $entity * @param array $visited */ - private function _cascadeDelete($entity, array &$visited) + private function _cascadeRemove($entity, array &$visited) { $class = $this->_em->getClassMetadata(get_class($entity)); foreach ($class->associationMappings as $assocMapping) { @@ -1396,10 +1378,10 @@ class UnitOfWork implements PropertyChangedListener ->getValue($entity); if ($relatedEntities instanceof Collection || is_array($relatedEntities)) { foreach ($relatedEntities as $relatedEntity) { - $this->_doDelete($relatedEntity, $visited); + $this->_doRemove($relatedEntity, $visited); } } else if ($relatedEntities !== null) { - $this->_doDelete($relatedEntities, $visited); + $this->_doRemove($relatedEntities, $visited); } } } @@ -1429,7 +1411,7 @@ class UnitOfWork implements PropertyChangedListener $this->_entityUpdates = array(); $this->_entityDeletions = array(); $this->_collectionDeletions = array(); - $this->_collectionCreations = array(); + //$this->_collectionCreations = array(); $this->_collectionUpdates = array(); $this->_commitOrderCalculator->clear(); } @@ -1574,8 +1556,6 @@ class UnitOfWork implements PropertyChangedListener /** * INTERNAL: - * For internal purposes only. - * * Sets a property value of the original data array of an entity. * * @param string $oid diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index 6ef7d4ffc..136a2647b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -25,8 +25,10 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->name = 'Roman'; $user->username = 'romanb'; $user->status = 'developer'; - $this->_em->save($user); + $this->_em->persist($user); + $this->_em->flush(); + $this->assertTrue(is_numeric($user->id)); $this->assertTrue($this->_em->contains($user)); @@ -56,14 +58,14 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertTrue($this->_em->contains($ph2)); // Delete - $this->_em->delete($user); - $this->assertTrue($this->_em->getUnitOfWork()->isRegisteredRemoved($user)); - $this->assertTrue($this->_em->getUnitOfWork()->isRegisteredRemoved($ph)); - $this->assertTrue($this->_em->getUnitOfWork()->isRegisteredRemoved($ph2)); + $this->_em->remove($user); + $this->assertTrue($this->_em->getUnitOfWork()->isScheduledForDelete($user)); + $this->assertTrue($this->_em->getUnitOfWork()->isScheduledForDelete($ph)); + $this->assertTrue($this->_em->getUnitOfWork()->isScheduledForDelete($ph2)); $this->_em->flush(); - $this->assertFalse($this->_em->getUnitOfWork()->isRegisteredRemoved($user)); - $this->assertFalse($this->_em->getUnitOfWork()->isRegisteredRemoved($ph)); - $this->assertFalse($this->_em->getUnitOfWork()->isRegisteredRemoved($ph2)); + $this->assertFalse($this->_em->getUnitOfWork()->isScheduledForDelete($user)); + $this->assertFalse($this->_em->getUnitOfWork()->isScheduledForDelete($ph)); + $this->assertFalse($this->_em->getUnitOfWork()->isScheduledForDelete($ph2)); } public function testOneToManyAssociationModification() @@ -81,7 +83,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->addPhonenumber($ph1); $user->addPhonenumber($ph2); - $this->_em->save($user); + $this->_em->persist($user); $this->_em->flush(); //$this->assertTrue($user->phonenumbers instanceof \Doctrine\ORM\PersistentCollection); @@ -111,7 +113,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->address = $address; // inverse side $address->user = $user; // owning side! - $this->_em->save($user); + $this->_em->persist($user); $this->_em->flush(); // Check that the foreign key has been set @@ -133,8 +135,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->groups[] = $group; $group->users[] = $user; - $this->_em->save($user); - $this->_em->save($group); + $this->_em->persist($user); $this->_em->flush(); @@ -163,10 +164,10 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $group->users[] = $user; } - $this->_em->save($user); // Saves the user, 'cause of post-insert ID + $this->_em->persist($user); $this->_em->flush(); - + // Check that there are indeed 10 links in the association table $count = $this->_em->getConnection()->execute("SELECT COUNT(*) FROM cms_users_groups", array())->fetchColumn(); @@ -189,7 +190,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->name = 'Guilherme'; $user->username = 'gblanco'; $user->status = 'developer'; - $this->_em->save($user); + $this->_em->persist($user); $this->_em->flush(); $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u"); @@ -226,7 +227,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->name = 'Guilherme'; $user->username = 'gblanco'; $user->status = 'developer'; - $this->_em->save($user); + $this->_em->persist($user); $this->_em->flush(); $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u join u.phonenumbers p"); @@ -242,7 +243,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->name = 'Guilherme'; $user->username = 'gblanco'; $user->status = 'developer'; - $this->_em->save($user); + $this->_em->persist($user); $this->_em->flush(); $query = $this->_em->createQuery("select u,p from Doctrine\Tests\Models\CMS\CmsUser u left join u.phonenumbers p"); @@ -270,9 +271,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->addGroup($group1); - $this->_em->save($user); - $this->_em->save($group1); - + $this->_em->persist($user); $this->_em->flush(); $this->_em->clear(); @@ -304,30 +303,5 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $query = $this->_em->createQuery("select u, g from Doctrine\Tests\Models\CMS\CmsUser u inner join u.groups g"); $this->assertEquals(0, count($query->getResultList())); - - /* RB: TEST */ - /* - $address = new CmsAddress; - $address->country = 'Germany'; - $address->zip = '103040'; - $address->city = 'Berlin'; - $address->user = $user; - $this->_em->save($address); - $this->_em->clear(); - - $proxy = $this->_em->getProxyGenerator()->getAssociationProxy($user, $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('address')); - - var_dump($proxy->getId()); - //var_dump(get_class($proxy)); - var_dump(get_class($proxy->user)); - //var_dump($proxy); - - //$proxy = $this->_em->getProxyGenerator()->getReferenceProxy('Doctrine\Tests\Models\CMS\CmsUser', 1); - - //echo $proxy->getId(); - //var_dump(serialize($proxy)); - */ - - } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php index f10de44eb..3d01110c5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php @@ -25,14 +25,14 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $person = new CompanyPerson; $person->setName('Roman S. Borschel'); - $this->_em->save($person); + $this->_em->persist($person); $employee = new CompanyEmployee; $employee->setName('Roman S. Borschel'); $employee->setSalary(100000); $employee->setDepartment('IT'); - $this->_em->save($employee); + $this->_em->persist($employee); $employee->setName('Guilherme Blanco'); $this->_em->flush(); @@ -86,13 +86,13 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $manager->setSalary(100000); $manager->setDepartment('IT'); $manager->setTitle('CTO'); - $this->_em->save($manager); + $this->_em->persist($manager); $this->_em->flush(); $manager->setName('Roman B.'); $manager->setSalary(119000); $manager->setTitle('CEO'); - $this->_em->save($manager); + $this->_em->persist($manager); $this->_em->flush(); $this->_em->clear(); @@ -119,8 +119,8 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertSame($manager, $wife->getSpouse()); $this->assertSame($wife, $manager->getSpouse()); - $this->_em->save($manager); - $this->_em->save($wife); + $this->_em->persist($manager); + $this->_em->persist($wife); $this->_em->flush(); @@ -155,8 +155,8 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(1, count($person2->getFriends())); - $this->_em->save($person1); - $this->_em->save($person2); + $this->_em->persist($person1); + $this->_em->persist($person2); $this->_em->flush(); diff --git a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php index df8ff2555..574329fb3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php @@ -24,7 +24,7 @@ class DetachedEntityTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->name = 'Roman'; $user->username = 'romanb'; $user->status = 'dev'; - $this->_em->save($user); + $this->_em->persist($user); $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php index 604edf4b7..64ee830dd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php @@ -21,7 +21,7 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase { $entity = new LifecycleCallbackTestEntity; $entity->value = 'hello'; - $this->_em->save($entity); + $this->_em->persist($entity); $this->_em->flush(); $this->assertTrue($entity->preSaveCallbackInvoked); diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php index 5d82b111c..1333f7dd0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php @@ -37,7 +37,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase $test = new OptimisticJoinedChild(); $test->name = 'child'; $test->whatever = 'whatever'; - $this->_em->save($test); + $this->_em->persist($test); $this->_em->flush(); $this->assertEquals(1, $test->version); @@ -66,7 +66,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase { $test = new OptimisticJoinedParent(); $test->name = 'parent'; - $this->_em->save($test); + $this->_em->persist($test); $this->_em->flush(); $this->assertEquals(1, $test->version); @@ -95,7 +95,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase { $test = new OptimisticStandard(); $test->name = 'test'; - $this->_em->save($test); + $this->_em->persist($test); $this->_em->flush(); $this->assertEquals(1, $test->version); diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php index 1f48be18d..0abc7fd68 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php @@ -38,7 +38,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati { $this->firstProduct->addCategory($this->firstCategory); $this->firstProduct->addCategory($this->secondCategory); - $this->_em->save($this->firstProduct); + $this->_em->persist($this->firstProduct); $this->_em->flush(); $this->assertForeignKeysContain($this->firstProduct->getId(), @@ -51,7 +51,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati { $this->firstProduct->addCategory($this->firstCategory); $this->firstProduct->addCategory($this->secondCategory); - $this->_em->save($this->firstProduct); + $this->_em->persist($this->firstProduct); $this->firstProduct->removeCategory($this->firstCategory); $this->_em->flush(); @@ -102,8 +102,8 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati $this->firstProduct->addCategory($this->secondCategory); $this->secondProduct->addCategory($this->firstCategory); $this->secondProduct->addCategory($this->secondCategory); - $this->_em->save($this->firstProduct); - $this->_em->save($this->secondProduct); + $this->_em->persist($this->firstProduct); + $this->_em->persist($this->secondProduct); $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php index 36a62c499..01f898a97 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php @@ -38,7 +38,7 @@ class ManyToManySelfReferentialAssociationTest extends AbstractManyToManyAssocia { $this->firstProduct->addRelated($this->firstRelated); $this->firstProduct->addRelated($this->secondRelated); - $this->_em->save($this->firstProduct); + $this->_em->persist($this->firstProduct); $this->_em->flush(); $this->assertForeignKeysContain($this->firstProduct->getId(), @@ -51,7 +51,7 @@ class ManyToManySelfReferentialAssociationTest extends AbstractManyToManyAssocia { $this->firstProduct->addRelated($this->firstRelated); $this->firstProduct->addRelated($this->secondRelated); - $this->_em->save($this->firstProduct); + $this->_em->persist($this->firstProduct); $this->firstProduct->removeRelated($this->firstRelated); $this->_em->flush(); @@ -91,8 +91,8 @@ class ManyToManySelfReferentialAssociationTest extends AbstractManyToManyAssocia $this->firstProduct->addRelated($this->secondRelated); $this->secondProduct->addRelated($this->firstRelated); $this->secondProduct->addRelated($this->secondRelated); - $this->_em->save($this->firstProduct); - $this->_em->save($this->secondProduct); + $this->_em->persist($this->firstProduct); + $this->_em->persist($this->secondProduct); $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php index 054679c31..0c050837e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php @@ -38,7 +38,7 @@ class ManyToManyUnidirectionalAssociationTest extends AbstractManyToManyAssociat { $this->firstCart->addProduct($this->firstProduct); $this->firstCart->addProduct($this->secondProduct); - $this->_em->save($this->firstCart); + $this->_em->persist($this->firstCart); $this->_em->flush(); $this->assertForeignKeysContain($this->firstCart->getId(), $this->firstProduct->getId()); @@ -49,7 +49,7 @@ class ManyToManyUnidirectionalAssociationTest extends AbstractManyToManyAssociat { $this->firstCart->addProduct($this->firstProduct); $this->firstCart->addProduct($this->secondProduct); - $this->_em->save($this->firstCart); + $this->_em->persist($this->firstCart); $this->firstCart->removeProduct($this->firstProduct); $this->_em->flush(); @@ -64,8 +64,8 @@ class ManyToManyUnidirectionalAssociationTest extends AbstractManyToManyAssociat $this->firstCart->addProduct($this->secondProduct); $this->secondCart->addProduct($this->firstProduct); $this->secondCart->addProduct($this->secondProduct); - $this->_em->save($this->firstCart); - $this->_em->save($this->secondCart); + $this->_em->persist($this->firstCart); + $this->_em->persist($this->secondCart); $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php index c11608ce9..63b5da564 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php @@ -25,7 +25,7 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->name = 'Roman'; $user->username = 'romanb'; $user->status = 'dev'; - $this->_em->save($user); + $this->_em->persist($user); $this->_em->flush(); $rsm = new ResultSetMapping; diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php index 8866d3230..c47d56a5c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php @@ -31,7 +31,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona public function testSavesAOneToManyAssociationWithCascadeSaveSet() { $this->product->addFeature($this->firstFeature); $this->product->addFeature($this->secondFeature); - $this->_em->save($this->product); + $this->_em->persist($this->product); $this->_em->flush(); $this->assertFeatureForeignKeyIs($this->product->getId(), $this->firstFeature); @@ -40,7 +40,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona public function testSavesAnEmptyCollection() { - $this->_em->save($this->product); + $this->_em->persist($this->product); $this->_em->flush(); $this->assertEquals(0, count($this->product->getFeatures())); @@ -48,7 +48,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona public function testDoesNotSaveAnInverseSideSet() { $this->product->brokenAddFeature($this->firstFeature); - $this->_em->save($this->product); + $this->_em->persist($this->product); $this->_em->flush(); $this->assertFeatureForeignKeyIs(null, $this->firstFeature); @@ -58,7 +58,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona { $this->product->addFeature($this->firstFeature); $this->product->addFeature($this->secondFeature); - $this->_em->save($this->product); + $this->_em->persist($this->product); $this->product->removeFeature($this->firstFeature); $this->_em->flush(); @@ -71,7 +71,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona { $this->product->addFeature($this->firstFeature); $this->product->addFeature($this->secondFeature); - $this->_em->save($this->product); + $this->_em->persist($this->product); $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php index 6d7199028..bb32d3238 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php @@ -30,7 +30,7 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio public function testSavesAOneToManyAssociationWithCascadeSaveSet() { $this->parent->addChild($this->firstChild); $this->parent->addChild($this->secondChild); - $this->_em->save($this->parent); + $this->_em->persist($this->parent); $this->_em->flush(); @@ -40,7 +40,7 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio public function testSavesAnEmptyCollection() { - $this->_em->save($this->parent); + $this->_em->persist($this->parent); $this->_em->flush(); $this->assertEquals(0, count($this->parent->getChildren())); @@ -48,7 +48,7 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio public function testDoesNotSaveAnInverseSideSet() { $this->parent->brokenAddChild($this->firstChild); - $this->_em->save($this->parent); + $this->_em->persist($this->parent); $this->_em->flush(); $this->assertForeignKeyIs(null, $this->firstChild); @@ -58,7 +58,7 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio { $this->parent->addChild($this->firstChild); $this->parent->addChild($this->secondChild); - $this->_em->save($this->parent); + $this->_em->persist($this->parent); $this->parent->removeChild($this->firstChild); $this->_em->flush(); @@ -71,7 +71,7 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio { $this->parent->addChild($this->firstChild); $this->parent->addChild($this->secondChild); - $this->_em->save($this->parent); + $this->_em->persist($this->parent); $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php index 606585e40..203f0f23e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php @@ -28,7 +28,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional public function testSavesAOneToOneAssociationWithCascadeSaveSet() { $this->customer->setCart($this->cart); - $this->_em->save($this->customer); + $this->_em->persist($this->customer); $this->_em->flush(); $this->assertCartForeignKeyIs($this->customer->getId()); @@ -36,7 +36,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional public function testDoesNotSaveAnInverseSideSet() { $this->customer->brokenSetCart($this->cart); - $this->_em->save($this->customer); + $this->_em->persist($this->customer); $this->_em->flush(); $this->assertCartForeignKeyIs(null); @@ -45,7 +45,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional public function testRemovesOneToOneAssociation() { $this->customer->setCart($this->cart); - $this->_em->save($this->customer); + $this->_em->persist($this->customer); $this->customer->removeCart(); $this->_em->flush(); @@ -88,7 +88,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional $cart->setPayment('paypal'); $customer->setCart($cart); - $this->_em->save($customer); + $this->_em->persist($customer); $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php index c2a533238..7ad9bf6ac 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php @@ -30,7 +30,7 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction public function testSavesAOneToOneAssociationWithCascadeSaveSet() { $this->customer->setMentor($this->mentor); - $this->_em->save($this->customer); + $this->_em->persist($this->customer); $this->_em->flush(); $this->assertForeignKeyIs($this->mentor->getId()); @@ -39,7 +39,7 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction public function testRemovesOneToOneAssociation() { $this->customer->setMentor($this->mentor); - $this->_em->save($this->customer); + $this->_em->persist($this->customer); $this->customer->removeMentor(); $this->_em->flush(); @@ -55,7 +55,7 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction $mentor->setName('Obi-wan Kenobi'); $customer->setMentor($mentor); - $this->_em->save($customer); + $this->_em->persist($customer); $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php index a8af8d5c1..fc1529d74 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php @@ -29,7 +29,7 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona public function testSavesAOneToOneAssociationWithCascadeSaveSet() { $this->product->setShipping($this->shipping); - $this->_em->save($this->product); + $this->_em->persist($this->product); $this->_em->flush(); $this->assertForeignKeyIs($this->shipping->getId()); @@ -38,7 +38,7 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona public function testRemovesOneToOneAssociation() { $this->product->setShipping($this->shipping); - $this->_em->save($this->product); + $this->_em->persist($this->product); $this->product->removeShipping(); $this->_em->flush(); @@ -81,7 +81,7 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $shipping->setDays('1'); $product->setShipping($shipping); - $this->_em->save($product); + $this->_em->persist($product); $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php index e4360836e..68e21bd5d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php @@ -25,7 +25,7 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->name = 'Roman'; $user->username = 'romanb'; $user->status = 'dev'; - $this->_em->save($user); + $this->_em->persist($user); $this->_em->flush(); diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php index e8dce76b2..10ab9fdee 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php @@ -26,7 +26,7 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->name = 'Guilherme'; $user->username = 'gblanco'; $user->status = 'developer'; - $this->_em->save($user); + $this->_em->persist($user); $this->_em->flush(); $this->_em->clear(); @@ -77,9 +77,9 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $article2->text = "This is an introduction to Symfony 2."; $user->addArticle($article2); - $this->_em->save($user); - $this->_em->save($article1); - $this->_em->save($article2); + $this->_em->persist($user); + $this->_em->persist($article1); + $this->_em->persist($article2); $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php b/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php index 6b8d6e98a..58ddee092 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php @@ -27,11 +27,12 @@ class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase { $product = new ECommerceProduct(); $product->setName('Doctrine Cookbook'); - $this->_em->save($product); - $id = $product->getId(); + $this->_em->persist($product); $this->_em->flush(); $this->_em->clear(); + + $id = $product->getId(); $productProxy = $this->_factory->getReferenceProxy('Doctrine\Tests\Models\ECommerce\ECommerceProduct', array('id' => $id)); $this->assertEquals('Doctrine Cookbook', $productProxy->getName()); diff --git a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php index 9ee31b085..9e8f07a28 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php @@ -29,32 +29,32 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $parent = new ParentEntity; $parent->setData('foobar'); - $this->_em->save($parent); + $this->_em->persist($parent); $child = new ChildEntity; $child->setData('thedata'); $child->setNumber(1234); - $this->_em->save($child); + $this->_em->persist($child); $relatedEntity = new RelatedEntity; $relatedEntity->setName('theRelatedOne'); $relatedEntity->setOwner($child); - $this->_em->save($relatedEntity); + $this->_em->persist($relatedEntity); $this->_em->flush(); $this->_em->clear(); - $query = $this->_em->createQuery("select e from Doctrine\Tests\ORM\Functional\ParentEntity e order by e.id asc"); + $query = $this->_em->createQuery("select e from Doctrine\Tests\ORM\Functional\ParentEntity e order by e.data asc"); $entities = $query->getResultList(); - + $this->assertEquals(2, count($entities)); - $this->assertTrue($entities[0] instanceof ParentEntity); - $this->assertTrue($entities[1] instanceof ChildEntity); $this->assertTrue(is_numeric($entities[0]->getId())); $this->assertTrue(is_numeric($entities[1]->getId())); + $this->assertTrue($entities[0] instanceof ParentEntity); + $this->assertTrue($entities[1] instanceof ChildEntity); $this->assertEquals('foobar', $entities[0]->getData()); $this->assertEquals('thedata', $entities[1]->getData()); $this->assertEquals(1234, $entities[1]->getNumber()); diff --git a/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php index 09d2ac4f5..30bba855b 100644 --- a/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php @@ -37,7 +37,7 @@ class InsertPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase $user->status = 'user'; $user->username = 'user' . $i; $user->name = 'Mr.Smith-' . $i; - $this->_em->save($user); + $this->_em->persist($user); if (($i % $batchSize) == 0) { $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index dff775bf3..2ace68f0b 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -40,9 +40,9 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase { $user = new ForumUser(); $user->username = 'romanb'; - $this->assertFalse($this->_unitOfWork->isRegisteredRemoved($user)); - $this->_unitOfWork->registerDeleted($user); - $this->assertFalse($this->_unitOfWork->isRegisteredRemoved($user)); + $this->assertFalse($this->_unitOfWork->isScheduledForDelete($user)); + $this->_unitOfWork->scheduleForDelete($user); + $this->assertFalse($this->_unitOfWork->isScheduledForDelete($user)); } @@ -60,28 +60,29 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase // Test $user = new ForumUser(); $user->username = 'romanb'; - $this->_unitOfWork->save($user); + $this->_unitOfWork->persist($user); // Check - $this->assertEquals(1, count($userPersister->getInserts())); // insert forced + $this->assertEquals(0, count($userPersister->getInserts())); $this->assertEquals(0, count($userPersister->getUpdates())); $this->assertEquals(0, count($userPersister->getDeletes())); - $this->assertTrue($this->_unitOfWork->isInIdentityMap($user)); + $this->assertFalse($this->_unitOfWork->isInIdentityMap($user)); // should no longer be scheduled for insert - $this->assertFalse($this->_unitOfWork->isRegisteredNew($user)); - // should have an id - $this->assertTrue(is_numeric($user->id)); + $this->assertTrue($this->_unitOfWork->isScheduledForInsert($user)); // Now lets check whether a subsequent commit() does anything $userPersister->reset(); // Test - $this->_unitOfWork->commit(); // shouldnt do anything + $this->_unitOfWork->commit(); - // Check. Verify that nothing happened. - $this->assertEquals(0, count($userPersister->getInserts())); + // Check. + $this->assertEquals(1, count($userPersister->getInserts())); $this->assertEquals(0, count($userPersister->getUpdates())); $this->assertEquals(0, count($userPersister->getDeletes())); + + // should have an id + $this->assertTrue(is_numeric($user->id)); } /** @@ -109,16 +110,18 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase $user->username = 'romanb'; $avatar = new ForumAvatar(); $user->avatar = $avatar; - $this->_unitOfWork->save($user); // save cascaded to avatar + $this->_unitOfWork->persist($user); // save cascaded to avatar + + $this->_unitOfWork->commit(); $this->assertTrue(is_numeric($user->id)); $this->assertTrue(is_numeric($avatar->id)); - $this->assertEquals(1, count($userPersister->getInserts())); // insert forced + $this->assertEquals(1, count($userPersister->getInserts())); $this->assertEquals(0, count($userPersister->getUpdates())); $this->assertEquals(0, count($userPersister->getDeletes())); - $this->assertEquals(1, count($avatarPersister->getInserts())); // insert forced + $this->assertEquals(1, count($avatarPersister->getInserts())); $this->assertEquals(0, count($avatarPersister->getUpdates())); $this->assertEquals(0, count($avatarPersister->getDeletes())); } @@ -130,13 +133,15 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase $entity = new NotifyChangedEntity; $entity->setData('thedata'); - $this->_unitOfWork->save($entity); + $this->_unitOfWork->persist($entity); + + $this->_unitOfWork->commit(); $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity)); $entity->setData('newdata'); - $this->assertTrue($this->_unitOfWork->isRegisteredDirty($entity)); + $this->assertTrue($this->_unitOfWork->isScheduledForUpdate($entity)); $this->assertEquals(array('data' => array('thedata', 'newdata')), $this->_unitOfWork->getEntityChangeSet($entity)); }