public function testClearingCollectionDoesNotInitialize() { $user = new CmsUser(); $user->username = "******"; $user->name = "Benjamin E."; $user->status = 'active'; $grp = new CmsGroup(); $grp->setName("The Dudes"); $grp->addUser($user); $user->addGroup($grp); $this->_em->persist($user); $this->_em->persist($grp); $this->_em->flush(); $this->_em->clear(); $this->assertEquals(1, $this->_em->getConnection()->fetchColumn("select count(*) from cms_users_groups")); $user2 = $this->_em->find(get_class($user), $user->id); $this->assertFalse($user2->groups->isInitialized()); $user2->groups->clear(); $this->assertFalse($user2->groups->isInitialized()); $this->_em->flush(); $this->assertFalse($user2->groups->isInitialized()); $this->assertEquals(0, $this->_em->getConnection()->fetchColumn("select count(*) from cms_users_groups")); }
public function addGroup(CmsGroup $group) { $this->groups[] = $group; $group->addUser($this); }
public function testRepeatedFlush() { $user1 = new CmsUser(); $user1->username = '******'; $user2 = new CmsTeamUser(); $user2->username = '******'; $user2->parent = $user1; $user3 = new CmsTeamUser(); $user3->username = '******'; $user3->parent = $user2; $group = new CmsGroup(); $group->id = '/functional/group'; $group->setName('foo'); $group->addUser($user1); $group->addUser($user2); $group->addUser($user3); $this->dm->persist($group); $this->assertCount(3, $group->getUsers()); $this->dm->flush(); $user4 = new CmsTeamUser(); $user4->username = '******'; $user4->parent = $user1; $group->addUser($user4); $this->assertCount(4, $group->getUsers()); $this->dm->flush(); $this->dm->getPhpcrSession()->removeItem($user2->id); $this->dm->getPhpcrSession()->save(); $this->dm->flush(); $this->assertInstanceOf('\\PHPCR\\NodeInterface', $user1->node); $this->assertCount(4, $group->getUsers()); $this->dm->clear(); $group = $this->dm->find(null, '/functional/group'); $group->getUsers()->first(); $this->assertCount(2, $group->getUsers()); $this->assertInstanceOf('\\PHPCR\\NodeInterface', $group->getUsers()->first()->node); }