Skip to content

Commit

Permalink
doctrine#1169 DDC-3343 - additional test cases: removing proxies from…
Browse files Browse the repository at this point in the history
… an extra-lazy collection still updates the owning side values
  • Loading branch information
Ocramius committed Jan 24, 2015
1 parent 6a2b7c2 commit d443d4f
Showing 1 changed file with 71 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
}
}

0 comments on commit d443d4f

Please sign in to comment.