diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php index 383940f5192..c323a44d8cf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php @@ -109,28 +109,60 @@ public function testThatASliceOfTheExtraLazyCollectionIsLoaded() /** * @group DDC-3343 */ - public function testEntityNotDeletedWhenRemovedFromExtraLazyAssociation() + public function testRemovesManagedElementFromOneToManyExtraLazyCollection() { - $user = new User(); - $tweet = new Tweet(); + list($userId, $tweetId) = $this->loadTweetFixture(); - $user->name = 'ocramius'; - $tweet->content = 'The cat is on the table'; + /* @var $user User */ + $user = $this->_em->find(User::CLASSNAME, $userId); - $user->addTweet($tweet); + $user->tweets->removeElement($this->_em->find(Tweet::CLASSNAME, $tweetId)); - $this->_em->persist($user); - $this->_em->persist($tweet); - $this->_em->flush(); $this->_em->clear(); /* @var $user User */ - $user = $this->_em->find(User::CLASSNAME, $user->id); - $tweet = $this->_em->find(Tweet::CLASSNAME, $tweet->id); - - $user->tweets->removeElement($tweet); + $user = $this->_em->find(User::CLASSNAME, $userId); $this->assertCount(0, $user->tweets); + } + + /** + * @group DDC-3343 + */ + public function testRemovesManagedElementFromOneToManyExtraLazyCollectionWithoutDeletingTheTargetEntityEntry() + { + list($userId, $tweetId) = $this->loadTweetFixture(); + + /* @var $user User */ + $user = $this->_em->find(User::CLASSNAME, $userId); + + $user->tweets->removeElement($this->_em->find(Tweet::CLASSNAME, $tweetId)); + + $this->_em->clear(); + + /* @var $tweet Tweet */ + $tweet = $this->_em->find(Tweet::CLASSNAME, $tweetId); + $this->assertInstanceOf( + Tweet::CLASSNAME, + $tweet, + 'Even though the collection is extra lazy, the tweet should not have been deleted' + ); + + $this->assertNull($tweet->author, 'Tweet author link has been removed'); + } + + /** + * @group DDC-3343 + */ + public function testRemovingManagedLazyProxyFromExtraLazyOneToManyDoesRemoveTheAssociationButNotTheEntity() + { + list($userId, $tweetId) = $this->loadTweetFixture(); + + /* @var $user User */ + $user = $this->_em->find(User::CLASSNAME, $userId); + $tweet = $this->_em->getReference(Tweet::CLASSNAME, $tweetId); + + $user->tweets->removeElement($this->_em->getReference(Tweet::CLASSNAME, $tweetId)); $this->_em->clear(); @@ -143,5 +175,31 @@ public function testEntityNotDeletedWhenRemovedFromExtraLazyAssociation() ); $this->assertNull($tweet->author); + + /* @var $user User */ + $user = $this->_em->find(User::CLASSNAME, $userId); + + $this->assertCount(0, $user->tweets); + } + + /** + * @return int[] ordered tuple: user id and tweet id + */ + private function loadTweetFixture() + { + $user = new User(); + $tweet = new Tweet(); + + $user->name = 'ocramius'; + $tweet->content = 'The cat is on the table'; + + $user->addTweet($tweet); + + $this->_em->persist($user); + $this->_em->persist($tweet); + $this->_em->flush(); + $this->_em->clear(); + + return array($user->id, $tweet->id); } }