Skip to content

Commit

Permalink
doctrine#1169 DDC-3343 - correcting query count assertions on extra-l…
Browse files Browse the repository at this point in the history
…azy specific tests (some DELETE operations became UPDATE operations)
  • Loading branch information
Ocramius committed Jan 24, 2015
1 parent 99c5650 commit 6a2b7c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
5 changes: 5 additions & 0 deletions lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Doctrine\ORM\Persisters\Collection;

use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Proxy\Proxy;
use Doctrine\ORM\PersistentCollection;

/**
Expand Down Expand Up @@ -165,6 +166,10 @@ public function removeElement(PersistentCollection $collection, $element)

$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);

Expand Down
27 changes: 7 additions & 20 deletions tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ public function testRemoveElementOneToMany()
$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();
Expand All @@ -501,7 +502,7 @@ public function testRemoveElementOneToMany()

$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
Expand Down Expand Up @@ -532,17 +533,10 @@ public function testRemovalOfManagedElementFromOneToManyJoinedInheritanceCollect

$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));
Expand Down Expand Up @@ -601,17 +595,10 @@ public function testRemovalOfNewManagedElementFromOneToManyJoinedInheritanceColl

$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.');
}
Expand Down

0 comments on commit 6a2b7c2

Please sign in to comment.