Skip to content

Instantly share code, notes, and snippets.

@doctrinebot
Created December 13, 2015 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doctrinebot/24c53dc10454cb82b1ec to your computer and use it in GitHub Desktop.
Save doctrinebot/24c53dc10454cb82b1ec to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-1630 - https://github.com/doctrine/doctrine2/issues/2272
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\Models\CMS\CmsGroup;
/**
* @group DDC-1630
*/
class DDC1630Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
$this->useModelSet('cms');
parent::setUp();
}
public function testIssueGetDeleteDiff()
{
$group = new CmsGroup();
$group->name = "test";
$this->_em->persist($group);
$this->_em->flush();
$user = new CmsUser();
$user->username = "beberlei";
$user->name = "Benjamin";
$user->status = "active";
$user->groups[] = $group;
$this->_em->persist($user);
$this->_em->flush();
$this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $user->groups);
$user = $this->_em->find(get_class($user), $user->id);
$user->groups->removeElement($group);
$this->assertEquals(1, count($user->groups->getDeleteDiff()));
$this->assertEquals(1, count($user->groups->getSnapshot()));
$group = new CmsGroup();
$group->name = "test";
$user->groups[] = $group;
$this->_em->persist($group);
$this->_em->flush();
$user = $this->_em->find(get_class($user), $user->id);
$this->assertEquals(1, count($user->groups), "We removed and added one, so the result should be one (not two!)");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment