1
0
mirror of synced 2025-01-31 12:32:59 +03:00

#1169 DDC-3343 - correcting query count assertions on extra-lazy specific tests (some DELETE operations became UPDATE operations)

This commit is contained in:
Marco Pivetta 2015-01-24 12:20:33 +01:00
parent 99c5650ba4
commit 6a2b7c2a8e
2 changed files with 12 additions and 20 deletions

View File

@ -20,6 +20,7 @@
namespace Doctrine\ORM\Persisters\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Proxy\Proxy;
use Doctrine\ORM\PersistentCollection;
/**
@ -165,6 +166,10 @@ class OneToManyPersister extends AbstractCollectionPersister
$targetMetadata = $this->em->getClassMetadata($mapping['targetEntity']);
if ($element instanceof Proxy && ! $element->__isInitialized()) {
$element->__load();
}
// clearing owning side value
$targetMetadata->reflFields[$mapping['mappedBy']]->setValue($element, null);

View File

@ -480,7 +480,8 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
$user->articles->removeElement($article);
$this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized.");
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
// NOTE: +2 queries because CmsArticle is a versioned entity, and that needs to be handled accordingly
$this->assertEquals($queryCount + 2, $this->getCurrentQueryCount());
// Test One to Many removal with Entity state as new
$article = new \Doctrine\Tests\Models\CMS\CmsArticle();
@ -501,7 +502,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
$user->articles->removeElement($article);
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a persisted entity should cause one query to be executed.");
$this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Removing a persisted entity will not cause queries when the owning side doesn't actually change.");
$this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized.");
// Test One to Many removal with Entity state as managed
@ -532,17 +533,10 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertFalse($otherClass->childClasses->isInitialized(), 'Collection is not initialized.');
$expectedQueryCount = $queryCount + 1;
if (! $this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) {
// the ORM emulates cascades in a JTI if the underlying platform does not support them
$expectedQueryCount = $queryCount + 2;
};
$this->assertEquals(
$expectedQueryCount,
$queryCount + 1,
$this->getCurrentQueryCount(),
'One removal per table in the JTI has been executed'
'The owning side of the association is updated'
);
$this->assertFalse($otherClass->childClasses->contains($childClass));
@ -601,17 +595,10 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
$otherClass->childClasses->removeElement($childClass);
$expectedQueryCount = $queryCount + 1;
if (! $this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) {
// the ORM emulates cascades in a JTI if the underlying platform does not support them
$expectedQueryCount = $queryCount + 2;
};
$this->assertEquals(
$expectedQueryCount,
$queryCount,
$this->getCurrentQueryCount(),
'Removing a persisted entity should cause two queries to be executed.'
'No queries are executed, as the owning side of the association is not actually updated.'
);
$this->assertFalse($otherClass->childClasses->isInitialized(), 'Collection is not initialized.');
}