#1169 DDC-3343 - correcting query count assertions on extra-lazy specific tests (some DELETE operations became UPDATE operations)
This commit is contained in:
parent
99c5650ba4
commit
6a2b7c2a8e
@ -20,6 +20,7 @@
|
|||||||
namespace Doctrine\ORM\Persisters\Collection;
|
namespace Doctrine\ORM\Persisters\Collection;
|
||||||
|
|
||||||
use Doctrine\Common\Collections\Criteria;
|
use Doctrine\Common\Collections\Criteria;
|
||||||
|
use Doctrine\Common\Proxy\Proxy;
|
||||||
use Doctrine\ORM\PersistentCollection;
|
use Doctrine\ORM\PersistentCollection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -165,6 +166,10 @@ class OneToManyPersister extends AbstractCollectionPersister
|
|||||||
|
|
||||||
$targetMetadata = $this->em->getClassMetadata($mapping['targetEntity']);
|
$targetMetadata = $this->em->getClassMetadata($mapping['targetEntity']);
|
||||||
|
|
||||||
|
if ($element instanceof Proxy && ! $element->__isInitialized()) {
|
||||||
|
$element->__load();
|
||||||
|
}
|
||||||
|
|
||||||
// clearing owning side value
|
// clearing owning side value
|
||||||
$targetMetadata->reflFields[$mapping['mappedBy']]->setValue($element, null);
|
$targetMetadata->reflFields[$mapping['mappedBy']]->setValue($element, null);
|
||||||
|
|
||||||
|
@ -480,7 +480,8 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$user->articles->removeElement($article);
|
$user->articles->removeElement($article);
|
||||||
|
|
||||||
$this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized.");
|
$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
|
// Test One to Many removal with Entity state as new
|
||||||
$article = new \Doctrine\Tests\Models\CMS\CmsArticle();
|
$article = new \Doctrine\Tests\Models\CMS\CmsArticle();
|
||||||
@ -501,7 +502,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
|
|
||||||
$user->articles->removeElement($article);
|
$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.");
|
$this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized.");
|
||||||
|
|
||||||
// Test One to Many removal with Entity state as managed
|
// 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.');
|
$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(
|
$this->assertEquals(
|
||||||
$expectedQueryCount,
|
$queryCount + 1,
|
||||||
$this->getCurrentQueryCount(),
|
$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));
|
$this->assertFalse($otherClass->childClasses->contains($childClass));
|
||||||
@ -601,17 +595,10 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
|
|
||||||
$otherClass->childClasses->removeElement($childClass);
|
$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(
|
$this->assertEquals(
|
||||||
$expectedQueryCount,
|
$queryCount,
|
||||||
$this->getCurrentQueryCount(),
|
$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.');
|
$this->assertFalse($otherClass->childClasses->isInitialized(), 'Collection is not initialized.');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user