当前位置: 首页>>代码示例>>PHP>>正文


PHP User::addGroup方法代码示例

本文整理汇总了PHP中Documents\User::addGroup方法的典型用法代码示例。如果您正苦于以下问题:PHP User::addGroup方法的具体用法?PHP User::addGroup怎么用?PHP User::addGroup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Documents\User的用法示例。


在下文中一共展示了User::addGroup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testManyReferenceAddAndPersist

 public function testManyReferenceAddAndPersist()
 {
     $user = new User();
     $user->addGroup(new Group('Group A'));
     $user->addGroup(new Group('Group B'));
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $user = $this->dm->find('Documents\\User', $user->getId());
     $groups = $user->getGroups();
     $this->assertCount(2, $groups);
     $this->assertFalse($groups->isInitialized());
     $user->addGroup(new Group('Group C'));
     $this->assertCount(3, $groups);
     $this->assertFalse($groups->isInitialized());
     $this->dm->persist($user);
     $this->dm->flush();
     $groups->initialize();
     $this->assertCount(3, $groups);
     $this->assertTrue($groups->isInitialized());
     $user->addGroup(new Group('Group D'));
     $this->assertCount(4, $groups);
     $this->assertTrue($groups->isInitialized());
     $this->dm->persist($user);
     $this->dm->flush();
     $this->assertCount(4, $groups);
     $this->assertTrue($groups->isInitialized());
 }
开发者ID:nclavaud,项目名称:mongodb-odm,代码行数:28,代码来源:GH909Test.php

示例2: setUp

 public function setUp()
 {
     parent::setUp();
     $this->ids = array();
     $groupA = new Group('groupA');
     $groupB = new Group('groupB');
     $profile = new Profile();
     $profile->setFirstname('Timothy');
     $tim = new User();
     $tim->setUsername('Tim');
     $tim->setHits(10);
     $tim->addGroup($groupA);
     $tim->addGroup($groupB);
     $tim->setProfile($profile);
     $this->dm->persist($tim);
     $john = new User();
     $john->setUsername('John');
     $john->setHits(10);
     $this->dm->persist($john);
     $this->dm->flush();
     $this->dm->clear();
     $this->ids['tim'] = $tim->getId();
     $this->ids['john'] = $john->getId();
     $this->fc = $this->dm->getFilterCollection();
 }
开发者ID:Wizkunde,项目名称:mongodb-odm,代码行数:25,代码来源:FilterTest.php

示例3: testSlaveOkayOnPersistentCollection

 public function testSlaveOkayOnPersistentCollection()
 {
     $user = new User();
     $user->addGroup(new Group('Test'));
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $user = $this->dm->getRepository('Documents\\User')->createQueryBuilder()->slaveOkay(false)->getQuery()->getSingleResult();
     $this->assertEquals(array(), $user->getGroups()->getHints());
     $this->dm->clear();
     $users = $this->dm->getRepository('Documents\\User')->createQueryBuilder()->getQuery()->execute();
     $this->assertEquals(array(), $users->getHints());
     $users = array_values($users->toArray());
     $user = $users[0];
     $this->assertEquals(array(), $user->getGroups()->getHints());
     $this->dm->clear();
     $user = $this->dm->getRepository('Documents\\User')->createQueryBuilder()->slaveOkay(true)->getQuery()->getSingleResult();
     $this->assertEquals(array(Query::HINT_SLAVE_OKAY => true), $user->getGroups()->getHints());
     $this->dm->clear();
     $users = $this->dm->getRepository('Documents\\User')->createQueryBuilder()->getQuery()->execute()->slaveOkay(true);
     $this->assertEquals(array(Query::HINT_SLAVE_OKAY => true), $users->getHints());
     $users = array_values($users->toArray());
     $user = $users[0];
     $this->assertEquals(array(Query::HINT_SLAVE_OKAY => true), $user->getGroups()->getHints());
     $this->dm->clear();
     $user = $this->dm->getRepository('Documents\\User')->createQueryBuilder()->getQuery()->getSingleResult();
     $groups = $user->getGroups();
     $groups->setHints(array(Query::HINT_SLAVE_OKAY => true));
     $this->assertEquals(array(Query::HINT_SLAVE_OKAY => true), $groups->getHints());
 }
开发者ID:romainneutron,项目名称:mongodb-odm,代码行数:30,代码来源:SlaveOkayTest.php

示例4: setUp

 public function setUp()
 {
     parent::setUp();
     $user = new User();
     $user->addGroup(new Group('Test'));
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
 }
开发者ID:nclavaud,项目名称:mongodb-odm,代码行数:9,代码来源:ReadPreferenceTest.php

示例5: testUnsetFromEmbeddedCollection

 public function testUnsetFromEmbeddedCollection()
 {
     $userRepository = $this->dm->getRepository('Documents\\User');
     $user = new User();
     $user->addGroup(new Group('group1'));
     $user->addGroup(new Group('group2'));
     $user->addGroup(new Group('group3'));
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $this->assertCount(3, $user->getGroups());
     $user = $userRepository->find($user->getId());
     $user->getGroups()->remove(0);
     $this->dm->flush();
     $this->dm->clear();
     $user = $userRepository->find($user->getId());
     $this->assertCount(2, $user->getGroups());
 }
开发者ID:Wizkunde,项目名称:mongodb-odm,代码行数:18,代码来源:RemoveTest.php

示例6: testFindByRefManyFull

 public function testFindByRefManyFull()
 {
     $user = new User();
     $group = new Group('group');
     $user->addGroup($group);
     $this->dm->persist($user);
     $this->dm->persist($group);
     $this->dm->flush();
     $this->assertSame($user, $this->dm->getRepository(User::class)->findOneBy(['groups' => $group]));
 }
开发者ID:dominium,项目名称:mongodb-odm,代码行数:10,代码来源:DocumentRepositoryTest.php

示例7: testUnsetFromEmbeddedCollection

 public function testUnsetFromEmbeddedCollection()
 {
     $user = new User();
     $user->setUsername('jon');
     $user->addGroup(new Group('test group 1'));
     $user->addGroup(new Group('test group 2'));
     $user->addGroup(new Group('test group 3'));
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $user = $this->dm->find('Documents\\User', $user->getId());
     $groups = $user->getGroups();
     unset($groups[0]);
     $this->assertEquals(2, count($user->getGroups()));
     $this->dm->flush();
     $this->dm->clear();
     $user = $this->dm->getRepository('Documents\\User')->findOneBy(array('username' => 'jon'));
     $this->assertEquals(2, count($user->getGroups()));
 }
开发者ID:jackbravo,项目名称:symfony-sandbox,代码行数:19,代码来源:RemoveTest.php

示例8: setUp

 public function setUp()
 {
     if (version_compare(phpversion('mongo'), '1.3.0', '<')) {
         $this->markTestSkipped('This test is not applicable to driver versions < 1.3.0');
     }
     parent::setUp();
     $user = new User();
     $user->addGroup(new Group('Test'));
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
 }
开发者ID:briareos,项目名称:mongodb-odm,代码行数:12,代码来源:ReadPreferenceTest.php

示例9: testManyReference

 public function testManyReference()
 {
     $user = new \Documents\User();
     $user->addGroup(new Group('Group 1'));
     $user->addGroup(new Group('Group 2'));
     $this->dm->persist($user);
     $this->dm->flush();
     $groups = $user->getGroups();
     $this->assertTrue($groups instanceof PersistentCollection);
     $this->assertTrue($groups[0]->getId() !== '');
     $this->assertTrue($groups[1]->getId() !== '');
     $user2 = $this->dm->createQuery('Documents\\User')->where('id', $user->getId())->getSingleResult();
     $groups = $user2->getGroups();
     $this->assertTrue($groups instanceof PersistentCollection);
     $this->assertTrue($groups[0] instanceof Group);
     $this->assertTrue($groups[1] instanceof Group);
     unset($groups[0]);
     $this->dm->flush();
     $this->dm->clear();
     $user3 = $this->dm->createQuery('Documents\\User')->where('id', $user->getId())->getSingleResult();
     $this->assertEquals(1, count($user2->getGroups()));
 }
开发者ID:poulikov,项目名称:mongodb-odm,代码行数:22,代码来源:ReferencesTest.php

示例10: testManyReference

 public function testManyReference()
 {
     $user = new \Documents\User();
     $user->addGroup(new Group('Group 1'));
     $user->addGroup(new Group('Group 2'));
     $this->dm->persist($user);
     $this->dm->flush();
     $groups = $user->getGroups();
     $this->assertTrue($groups instanceof PersistentCollection);
     $this->assertTrue($groups[0]->getId() !== '');
     $this->assertTrue($groups[1]->getId() !== '');
     $this->dm->clear();
     $qb = $this->dm->createQueryBuilder('Documents\\User')->field('id')->equals($user->getId());
     $query = $qb->getQuery();
     $user2 = $query->getSingleResult();
     $groups = $user2->getGroups();
     $this->assertFalse($groups->isInitialized());
     $groups->count();
     $this->assertFalse($groups->isInitialized());
     $groups->isEmpty();
     $this->assertFalse($groups->isInitialized());
     $groups = $user2->getGroups();
     $this->assertTrue($groups instanceof PersistentCollection);
     $this->assertTrue($groups[0] instanceof Group);
     $this->assertTrue($groups[1] instanceof Group);
     $this->assertTrue($groups->isInitialized());
     unset($groups[0]);
     $groups[1]->setName('test');
     $this->dm->flush();
     $this->dm->clear();
     $qb = $this->dm->createQueryBuilder('Documents\\User')->field('id')->equals($user->getId());
     $query = $qb->getQuery();
     $user3 = $query->getSingleResult();
     $groups = $user3->getGroups();
     $this->assertEquals('test', $groups[0]->getName());
     $this->assertEquals(1, count($groups));
 }
开发者ID:jackbravo,项目名称:symfony-sandbox,代码行数:37,代码来源:ReferencesTest.php

示例11: testQueryReferences

 public function testQueryReferences()
 {
     $group = new \Documents\Group('Test Group');
     $user = new User();
     $user->setUsername('cool');
     $user->addGroup($group);
     $this->dm->persist($user);
     $this->dm->flush();
     $qb = $this->dm->createQueryBuilder('Documents\\User')->field('groups')->references($group);
     $query = $qb->getQuery();
     $user2 = $query->getSingleResult();
     $this->assertSame($user, $user2);
 }
开发者ID:romainneutron,项目名称:mongodb-odm,代码行数:13,代码来源:QueryTest.php

示例12: testFindByRefManyFull

 public function testFindByRefManyFull()
 {
     $user = new User();
     $group = new Group('group');
     $user->addGroup($group);
     $this->dm->persist($user);
     $this->dm->persist($group);
     $this->dm->flush();
     $query = $this->dm->getUnitOfWork()->getDocumentPersister(User::class)->prepareQueryOrNewObj(['groups' => $group]);
     $expectedQuery = ['groups' => ['$elemMatch' => ['$id' => new \MongoId($group->getId())]]];
     $this->assertEquals($expectedQuery, $query);
     $this->assertSame($user, $this->dm->getRepository(User::class)->findOneBy(['groups' => $group]));
 }
开发者ID:alcaeus,项目名称:mongodb-odm,代码行数:13,代码来源:DocumentRepositoryTest.php

示例13: testPrimeReferencesInvokesPrimer

 /**
  * @group replication_lag
  */
 public function testPrimeReferencesInvokesPrimer()
 {
     $group1 = new Group();
     $group2 = new Group();
     $account = new Account();
     $user = new User();
     $user->addGroup($group1);
     $user->addGroup($group2);
     $user->setAccount($account);
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $invokedArgs = array();
     $primer = function (DocumentManager $dm, ClassMetadata $class, array $ids, array $hints) use(&$invokedArgs) {
         $invokedArgs[] = func_get_args();
     };
     $this->dm->createQueryBuilder('Documents\\User')->field('account')->prime($primer)->field('groups')->prime($primer)->slaveOkay(true)->getQuery()->toArray();
     $this->assertCount(2, $invokedArgs, 'Primer was invoked once for each referenced class.');
     $this->assertArrayHasKey(Query::HINT_SLAVE_OKAY, $invokedArgs[0][3], 'Primer was invoked with UnitOfWork hints from original query.');
     $this->assertTrue($invokedArgs[0][3][Query::HINT_SLAVE_OKAY], 'Primer was invoked with UnitOfWork hints from original query.');
     $accountIds = array($account->getId());
     $groupIds = array($group1->getId(), $group2->getId());
     $this->assertEquals($accountIds, $invokedArgs[0][2]);
     $this->assertEquals($groupIds, $invokedArgs[1][2]);
 }
开发者ID:alcaeus,项目名称:mongodb-odm,代码行数:28,代码来源:ReferencePrimerTest.php

示例14: testReplaceEntireGroupsArray

 public function testReplaceEntireGroupsArray()
 {
     $account = new Account();
     $account->setName('Jon Test Account');
     $user = new User();
     $user->setUsername('jon333');
     $user->setPassword('changeme');
     $user->setAccount($account);
     $group2 = new Group('member');
     $user->addGroup(new Group('administrator'));
     $user->addGroup($group2);
     $user->addGroup(new Group('moderator'));
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $user = $this->dm->find('Documents\\User', $user->getId());
     $this->assertNotNull($user);
     // Issue is collection must be initialized
     $groups = $user->getGroups();
     $groups[0];
     // initialize collection
     // reffectively remove two of the groups
     //$user->getGroups()->clear();
     //$user->getGroups()->add($group2);
     $user->setGroups(array($group2));
     $this->assertEquals(1, count($user->getGroups()));
     $this->dm->flush();
     $this->dm->clear();
     $user = $this->dm->find('Documents\\User', $user->getId());
     $this->assertEquals(1, count($user->getGroups()));
 }
开发者ID:im286er,项目名称:ent,代码行数:31,代码来源:FunctionalTest.php

示例15: testReplaceGroups

 public function testReplaceGroups()
 {
     $this->dm->getUnitOfWork()->setDocumentPersister('Documents\\User', new BasicDocumentPersister($this->dm, $this->classMetadata));
     $account = new Account();
     $account->setName('Jon Test Account');
     $user = new User();
     $user->setUsername('jon');
     $user->setPassword('changeme');
     $user->setAccount($account);
     $user->addGroup(new Group('administrator'));
     $user->addGroup(new Group('member'));
     $user->addGroup(new Group('moderator'));
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     unset($user, $account);
     $user = $this->dm->findOne('Documents\\User');
     $user->removeGroup('moderator');
     $user->removeGroup('member');
     $this->assertEquals(1, count($user->getGroups()));
     $user->addGroup(new Group('seller'));
     $user->addGroup(new Group('supplier'));
     $this->assertEquals(3, count($user->getGroups()));
     $this->dm->getUnitOfWork()->setDocumentPersister('Documents\\User', $this->persister);
     $this->persister->expects($this->once())->method('update')->with($user);
     $this->dm->getUnitOfWork()->computeChangeSets();
     $update = $this->persister->prepareUpdateData($user);
     $this->assertFalse(array_key_exists('$set', $update));
     $this->assertFalse(array_key_exists('$unset', $update));
     $this->assertTrue(array_key_exists('$pullAll', $update));
     $this->assertTrue(array_key_exists('groups', $update['$pullAll']));
     $this->assertEquals(2, count($update['$pullAll']['groups']));
     $this->assertTrue(array_key_exists('$pushAll', $update));
     $this->assertTrue(array_key_exists('groups', $update['$pushAll']));
     $this->assertEquals(2, count($update['$pushAll']['groups']));
     $this->dm->flush();
     $this->dm->clear();
     unset($user);
     $user = $this->dm->findOne('Documents\\User');
     $this->assertEquals(3, count($user->getGroups()));
 }
开发者ID:poulikov,项目名称:mongodb-odm,代码行数:41,代码来源:BasicDocumentPersisterTest.php


注:本文中的Documents\User::addGroup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。