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


PHP User::setAccount方法代码示例

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


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

示例1: testFindByRefOneFull

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

示例2: testFindByRefOneWithoutTargetDocumentFull

 public function testFindByRefOneWithoutTargetDocumentFull()
 {
     $user = new User();
     $account = new Account('name');
     $user->setAccount($account);
     $this->dm->persist($user);
     $this->dm->persist($account);
     $this->dm->flush();
     $query = $this->dm->getUnitOfWork()->getDocumentPersister(Account::class)->prepareQueryOrNewObj(['user' => $user]);
     $expectedQuery = ['user.$ref' => 'users', 'user.$id' => new \MongoId($user->getId()), 'user.$db' => DOCTRINE_MONGODB_DATABASE];
     $this->assertEquals($expectedQuery, $query);
     $this->assertSame($account, $this->dm->getRepository(Account::class)->findOneBy(['user' => $user]));
 }
开发者ID:alcaeus,项目名称:mongodb-odm,代码行数:13,代码来源:DocumentRepositoryTest.php

示例3: testOneReference

 public function testOneReference()
 {
     $account = new Account();
     $account->setName('Test Account');
     $user = new User();
     $user->setUsername('jwage');
     $user->setAccount($account);
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->flush();
     $this->dm->clear();
     $accountId = $user->getAccount()->getId();
     $user2 = $this->dm->createQuery('Documents\\User')->where('id', $user->getId())->getSingleResult();
 }
开发者ID:poulikov,项目名称:mongodb-odm,代码行数:14,代码来源:ReferencesTest.php

示例4: testOneReference

 public function testOneReference()
 {
     $account = new Account();
     $account->setName('Test Account');
     $user = new User();
     $user->setUsername('jwage');
     $user->setAccount($account);
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->flush();
     $this->dm->clear();
     $accountId = $user->getAccount()->getId();
     $qb = $this->dm->createQueryBuilder('Documents\\User')->field('id')->equals($user->getId());
     $query = $qb->getQuery();
     $user2 = $query->getSingleResult();
 }
开发者ID:jackbravo,项目名称:symfony-sandbox,代码行数:16,代码来源:ReferencesTest.php

示例5: testCascadeInsertUpdateAndRemove

 public function testCascadeInsertUpdateAndRemove()
 {
     $account = new Account();
     $account->setName('Jon Test Account');
     $user = new User();
     $user->setUsername('jon');
     $user->setPassword('changeme');
     $user->setAccount($account);
     $this->dm->persist($user);
     $this->dm->flush();
     $account->setName('w00t');
     $this->dm->flush();
     $this->assertEquals('w00t', $user->getAccount()->getName());
     $this->dm->remove($user);
     $this->dm->flush();
     $this->dm->clear();
 }
开发者ID:alcaeus,项目名称:mongodb-odm,代码行数:17,代码来源:PersistingTest.php

示例6: testRemove

 public function testRemove()
 {
     $account = new Account();
     $account->setName('Jon Test Account');
     $user = new User();
     $user->setUsername('jon');
     $user->setPassword('changeme');
     $user->setAccount($account);
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->remove($user);
     $this->dm->flush();
     $account = $this->dm->find('Documents\\Account', $account->getId());
     $this->assertNull($account);
     $user = $this->dm->find('Documents\\User', $user->getId());
     $this->assertNull($user);
 }
开发者ID:Wizkunde,项目名称:mongodb-odm,代码行数:17,代码来源:RemoveTest.php

示例7: 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

示例8: 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

示例9: 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

示例10: testFindUser

 public function testFindUser()
 {
     $account = new Account();
     $account->setName('Jon Test Account');
     $user1 = new CustomUser();
     $user1->setId('userId');
     $user1->setUsername('user1');
     $user1->setPassword('changeme');
     $user1->setAccount($account);
     $user2 = new User();
     $user2->setUsername('user2');
     $user2->setPassword('changeme');
     $user2->setAccount($account);
     $user3 = new User();
     $user3->setUsername('user3');
     $user3->setPassword('changeme');
     $user3->setAccount($account);
     $this->dm->persist($user1);
     $this->dm->persist($user2);
     $this->dm->persist($user3);
     $this->dm->flush();
     $this->dm->clear();
     unset($user1, $user2, $user3);
     $user = $this->dm->find('Documents\\CustomUser', 'userId');
     $this->assertNotNull($user);
     $this->assertEquals('userId', $user->getId());
     $this->assertEquals('user1', $user->getUsername());
     $this->dm->clear();
     unset($user);
     $this->assertNull($this->dm->find('Documents\\User', 'userId'));
     $this->assertNull($this->dm->find('Documents\\CustomUser', 'asd'));
 }
开发者ID:alcaeus,项目名称:mongodb-odm,代码行数:32,代码来源:CustomIdTest.php


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