Commit 7297ac7b authored by romanb's avatar romanb

[2.0] Addressed #2363.

parent 82be4bf0
......@@ -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);
}
/**
......
......@@ -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();
......
......@@ -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
......
......@@ -166,7 +166,7 @@ class ResultSetMapping
if ( ! $this->isMixed && $this->fieldMappings) {
$this->isMixed = true;
}
}
}
/**
* @return boolean
......
This diff is collapsed.
......@@ -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
......@@ -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();
......
......@@ -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();
......
......@@ -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);
......
......@@ -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);
......
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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;
......
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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());
......
......@@ -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());
......
......@@ -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();
......
......@@ -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));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment