Skip to content

Commit

Permalink
doctrine#1169 DDC-3343 - updating test expectations - one-to-many ch…
Browse files Browse the repository at this point in the history
…anges should be no-op unless orphan removal is specified.
  • Loading branch information
Ocramius committed Jan 29, 2015
1 parent ba04c98 commit 579b710
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,5 +649,109 @@ private function loadFixture()

$this->topic = $article1->topic;
$this->phonenumber = $phonenumber1->phonenumber;

}

/**
* @group DDC-3343
*/
public function testRemoveManagedElementFromOneToManyExtraLazyCollectionIsNoOp()
{
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 $user User */
$user = $this->_em->find(User::CLASSNAME, $userId);

$this->assertCount(1, $user->tweets, 'Element was not removed - need to update the owning side first');
}

/**
* @group DDC-3343
*/
public function testRemoveManagedElementFromOneToManyExtraLazyCollectionWithoutDeletingTheTargetEntityEntryIsNoOp()
{
list($userId, $tweetId) = $this->loadTweetFixture();

/* @var $user User */
$user = $this->_em->find(User::CLASSNAME, $userId);

$e = $this->_em->find(Tweet::CLASSNAME, $tweetId);

$user->tweets->removeElement($e);

$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->assertInstanceOf(
User::CLASSNAME,
$tweet->author,
'Tweet author link has not been removed - need to update the owning side first'
);
}

/**
* @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();

/* @var $tweet Tweet */
$tweet = $this->_em->find(Tweet::CLASSNAME, $tweet->id);
$this->assertInstanceOf(
Tweet::CLASSNAME,
$tweet,
'Even though the collection is extra lazy, the tweet should not have been deleted'
);

$this->assertNull($tweet->author);

/* @var $user User */
$user = $this->_em->find(User::CLASSNAME, $userId);

$this->assertCount(1, $user->tweets, 'Element was not removed - need to update the owning side first');
}

/**
* @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);
}
}

0 comments on commit 579b710

Please sign in to comment.