當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。