本文整理汇总了PHP中Doctrine\Tests\Models\CMS\CmsUser::addPhonenumber方法的典型用法代码示例。如果您正苦于以下问题:PHP CmsUser::addPhonenumber方法的具体用法?PHP CmsUser::addPhonenumber怎么用?PHP CmsUser::addPhonenumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Tests\Models\CMS\CmsUser
的用法示例。
在下文中一共展示了CmsUser::addPhonenumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadFixtures
private function loadFixtures()
{
$u1 = new CmsUser();
$u2 = new CmsUser();
$u3 = new CmsUser();
$u1->setEmail(new CmsEmail());
$u1->setAddress(new CmsAddress());
$u1->addPhonenumber(new CmsPhonenumber());
$u2->setEmail(new CmsEmail());
$u2->setAddress(new CmsAddress());
$u2->addPhonenumber(new CmsPhonenumber());
$u2->addPhonenumber(new CmsPhonenumber());
$u3->setEmail(new CmsEmail());
$u3->setAddress(new CmsAddress());
$u3->addPhonenumber(new CmsPhonenumber());
$u3->addPhonenumber(new CmsPhonenumber());
$u3->addPhonenumber(new CmsPhonenumber());
$u1->name = 'Test 1';
$u1->username = '1test';
$u1->status = 'developer';
$u1->email->email = 'email@test1.com';
$u1->address->zip = '111111111';
$u1->address->city = 'Some City 1';
$u1->address->country = 'Some Country 2';
$u1->phonenumbers[0]->phonenumber = "(11) 1111-1111";
$u2->name = 'Test 2';
$u2->username = '2test';
$u2->status = 'developer';
$u2->email->email = 'email@test2.com';
$u2->address->zip = '222222222';
$u2->address->city = 'Some City 2';
$u2->address->country = 'Some Country 2';
$u2->phonenumbers[0]->phonenumber = "(22) 1111-1111";
$u2->phonenumbers[1]->phonenumber = "(22) 2222-2222";
$u3->name = 'Test 3';
$u3->username = '3test';
$u3->status = 'developer';
$u3->email->email = 'email@test3.com';
$u3->address->zip = '33333333';
$u3->address->city = 'Some City 3';
$u3->address->country = 'Some Country 3';
$u3->phonenumbers[0]->phonenumber = "(33) 1111-1111";
$u3->phonenumbers[1]->phonenumber = "(33) 2222-2222";
$u3->phonenumbers[2]->phonenumber = "(33) 3333-3333";
$this->_em->persist($u1);
$this->_em->persist($u2);
$this->_em->persist($u3);
$this->_em->flush();
$this->_em->clear();
$this->fixtures = array($u1, $u2, $u3);
}
示例2: testSerializeUnserializeModifyMerge
public function testSerializeUnserializeModifyMerge()
{
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$user = new CmsUser();
$user->name = 'Guilherme';
$user->username = 'gblanco';
$user->status = 'developer';
$ph1 = new CmsPhonenumber();
$ph1->phonenumber = 1234;
$user->addPhonenumber($ph1);
$this->_em->persist($user);
$this->_em->flush();
$this->assertTrue($this->_em->contains($user));
$this->assertTrue($user->phonenumbers->isInitialized());
$serialized = serialize($user);
$this->_em->clear();
$this->assertFalse($this->_em->contains($user));
unset($user);
$user = unserialize($serialized);
$ph2 = new CmsPhonenumber();
$ph2->phonenumber = 56789;
$user->addPhonenumber($ph2);
$this->assertEquals(2, count($user->getPhonenumbers()));
$this->assertFalse($this->_em->contains($user));
$this->_em->persist($ph2);
// Merge back in
$user = $this->_em->merge($user);
// merge cascaded to phonenumbers
$this->_em->flush();
$this->assertTrue($this->_em->contains($user));
$this->assertEquals(2, count($user->getPhonenumbers()));
$phonenumbers = $user->getPhonenumbers();
$this->assertTrue($this->_em->contains($phonenumbers[0]));
$this->assertTrue($this->_em->contains($phonenumbers[1]));
}
示例3: testJoinedOneToManyNativeQuery
public function testJoinedOneToManyNativeQuery()
{
$user = new CmsUser();
$user->name = 'Roman';
$user->username = 'romanb';
$user->status = 'dev';
$phone = new CmsPhonenumber();
$phone->phonenumber = 424242;
$user->addPhonenumber($phone);
$this->_em->persist($user);
$this->_em->flush();
$this->_em->clear();
$rsm = new ResultSetMapping();
$rsm->addEntityResult('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'u');
$rsm->addFieldResult('u', $this->platform->getSQLResultCasing('id'), 'id');
$rsm->addFieldResult('u', $this->platform->getSQLResultCasing('name'), 'name');
$rsm->addFieldResult('u', $this->platform->getSQLResultCasing('status'), 'status');
$rsm->addJoinedEntityResult('Doctrine\\Tests\\Models\\CMS\\CmsPhonenumber', 'p', 'u', 'phonenumbers');
$rsm->addFieldResult('p', $this->platform->getSQLResultCasing('phonenumber'), 'phonenumber');
$query = $this->_em->createNativeQuery('SELECT id, name, status, phonenumber FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username = ?', $rsm);
$query->setParameter(1, 'romanb');
$users = $query->getResult();
$this->assertEquals(1, count($users));
$this->assertTrue($users[0] instanceof CmsUser);
$this->assertEquals('Roman', $users[0]->name);
$this->assertTrue($users[0]->getPhonenumbers() instanceof \Doctrine\ORM\PersistentCollection);
$this->assertTrue($users[0]->getPhonenumbers()->isInitialized());
$this->assertEquals(1, count($users[0]->getPhonenumbers()));
$phones = $users[0]->getPhonenumbers();
$this->assertEquals(424242, $phones[0]->phonenumber);
$this->assertTrue($phones[0]->getUser() === $users[0]);
}
示例4: testSerializeUnserializeModifyMerge
public function testSerializeUnserializeModifyMerge()
{
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$user = new CmsUser;
$user->name = 'Guilherme';
$user->username = 'gblanco';
$user->status = 'developer';
$ph1 = new CmsPhonenumber;
$ph1->phonenumber = "1234";
$user->addPhonenumber($ph1);
$this->_em->persist($user);
$this->_em->flush();
$this->assertTrue($this->_em->contains($user));
$this->assertTrue($user->phonenumbers->isInitialized());
$serialized = serialize($user);
$this->_em->clear();
$this->assertFalse($this->_em->contains($user));
unset($user);
$user = unserialize($serialized);
$this->assertEquals(1, count($user->getPhonenumbers()), "Pre-Condition: 1 Phonenumber");
$ph2 = new CmsPhonenumber;
$ph2->phonenumber = "56789";
$user->addPhonenumber($ph2);
$oldPhonenumbers = $user->getPhonenumbers();
$this->assertEquals(2, count($oldPhonenumbers), "Pre-Condition: 2 Phonenumbers");
$this->assertFalse($this->_em->contains($user));
$this->_em->persist($ph2);
// Merge back in
$user = $this->_em->merge($user); // merge cascaded to phonenumbers
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $user->phonenumbers[0]->user);
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $user->phonenumbers[1]->user);
$im = $this->_em->getUnitOfWork()->getIdentityMap();
$this->_em->flush();
$this->assertTrue($this->_em->contains($user), "Failed to assert that merged user is contained inside EntityManager persistence context.");
$phonenumbers = $user->getPhonenumbers();
$this->assertNotSame($oldPhonenumbers, $phonenumbers, "Merge should replace the Detached Collection with a new PersistentCollection.");
$this->assertEquals(2, count($phonenumbers), "Failed to assert that two phonenumbers are contained in the merged users phonenumber collection.");
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $phonenumbers[1]);
$this->assertTrue($this->_em->contains($phonenumbers[1]), "Failed to assert that second phonenumber in collection is contained inside EntityManager persistence context.");
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $phonenumbers[0]);
$this->assertTrue($this->_em->getUnitOfWork()->isInIdentityMap($phonenumbers[0]));
$this->assertTrue($this->_em->contains($phonenumbers[0]), "Failed to assert that first phonenumber in collection is contained inside EntityManager persistence context.");
}
示例5: testOneToManyAssociationModification
public function testOneToManyAssociationModification()
{
$user = new CmsUser();
$user->name = 'Roman';
$user->username = 'romanb';
$user->status = 'developer';
$ph1 = new CmsPhonenumber();
$ph1->phonenumber = "0301234";
$ph2 = new CmsPhonenumber();
$ph2->phonenumber = "987654321";
$user->addPhonenumber($ph1);
$user->addPhonenumber($ph2);
$this->_em->save($user);
$this->_em->flush();
//$this->assertTrue($user->phonenumbers instanceof \Doctrine\ORM\PersistentCollection);
// Remove the first element from the collection
unset($user->phonenumbers[0]);
$ph1->user = null;
// owning side!
$this->_em->flush();
$this->assertEquals(1, count($user->phonenumbers));
$this->assertNull($ph1->user);
}
示例6: setUp
protected function setUp()
{
$this->useModelSet('cms');
parent::setUp();
$user = new CmsUser();
$user->status = 'dev';
$user->username = 'romanb';
$user->name = 'Roman B.';
$phone = new CmsPhonenumber();
$phone->phonenumber = '123456';
$user->addPhonenumber($phone);
$this->_em->persist($user);
$this->_em->flush();
$this->userId = $user->getId();
$this->_em->clear();
}
示例7: createAndPersistUser
protected function createAndPersistUser()
{
$user = new CmsUser();
$user->name = 'Luka';
$user->username = 'lukacho';
$user->status = 'developer';
foreach (array(1111, 2222, 3333, 4444) as $number) {
$phone = new CmsPhonenumber();
$phone->phonenumber = $number;
$user->addPhonenumber($phone);
}
foreach (array('Moshers', 'Headbangers') as $groupName) {
$group = new CmsGroup();
$group->setName($groupName);
$user->addGroup($group);
}
$this->_em->persist($user);
return $user;
}
示例8: testOrphanRemoval
public function testOrphanRemoval()
{
$user = new CmsUser();
$user->status = 'dev';
$user->username = 'romanb';
$user->name = 'Roman B.';
$phone = new CmsPhonenumber();
$phone->phonenumber = '123456';
$user->addPhonenumber($phone);
$this->_em->persist($user);
$this->_em->flush();
$userId = $user->getId();
$this->_em->clear();
$userProxy = $this->_em->getReference('Doctrine\\Tests\\Models\\CMS\\CmsUser', $userId);
$this->_em->remove($userProxy);
$this->_em->flush();
$this->_em->clear();
$query = $this->_em->createQuery('SELECT u FROM Doctrine\\Tests\\Models\\CMS\\CmsUser u');
$result = $query->getResult();
$this->assertEquals(0, count($result), 'CmsUser should be removed by EntityManager');
$query = $this->_em->createQuery('SELECT p FROM Doctrine\\Tests\\Models\\CMS\\CmsPhonenumber p');
$result = $query->getResult();
$this->assertEquals(0, count($result), 'CmsPhonenumber should be removed by orphanRemoval');
}
示例9: testMultipleEntityResults
/**
* @group DDC-1663
* DQL : SELECT u, a, COUNT(p) AS numphones FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.address a JOIN u.phonenumbers p
*/
public function testMultipleEntityResults()
{
$user = new CmsUser();
$user->name = 'Fabio B. Silva';
$user->username = 'FabioBatSilva';
$user->status = 'dev';
$addr = new CmsAddress();
$addr->country = 'Brazil';
$addr->zip = 10827;
$addr->city = 'São Paulo';
$phone = new CmsPhonenumber();
$phone->phonenumber = 424242;
$user->setAddress($addr);
$user->addPhonenumber($phone);
$this->_em->clear();
$this->_em->persist($user);
$this->_em->flush();
$this->_em->clear();
$repository = $this->_em->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser');
$query = $repository->createNativeNamedQuery('fetchMultipleJoinsEntityResults');
$result = $query->getResult();
$this->assertEquals(1, count($result));
$this->assertTrue(is_array($result[0]));
$this->assertInstanceOf('Doctrine\\Tests\\Models\\CMS\\CmsUser', $result[0][0]);
$this->assertEquals('Fabio B. Silva', $result[0][0]->name);
$this->assertInstanceOf('Doctrine\\Tests\\Models\\CMS\\CmsAddress', $result[0][0]->getAddress());
$this->assertTrue($result[0][0]->getAddress()->getUser() == $result[0][0]);
$this->assertEquals('Brazil', $result[0][0]->getAddress()->getCountry());
$this->assertEquals(10827, $result[0][0]->getAddress()->getZipCode());
$this->assertEquals(1, $result[0]['numphones']);
}
示例10: testOneToOneMergeSetNull
/**
* @group DDC-634
*/
public function testOneToOneMergeSetNull()
{
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
$user = new CmsUser();
$user->username = "beberlei";
$user->name = "Benjamin E.";
$user->status = 'active';
$ph = new CmsPhonenumber();
$ph->phonenumber = "12345";
$user->addPhonenumber($ph);
$this->_em->persist($user);
$this->_em->persist($ph);
$this->_em->flush();
$this->_em->clear();
$ph->user = null;
$managedPh = $this->_em->merge($ph);
$this->_em->flush();
$this->_em->clear();
$this->assertNull($this->_em->find(get_class($ph), $ph->phonenumber)->getUser());
}
示例11: testOneToManyCascadeRemove
public function testOneToManyCascadeRemove()
{
$user = new CmsUser();
$user->name = 'Guilherme';
$user->username = 'gblanco';
$user->status = 'developer';
for ($i = 0; $i < 3; ++$i) {
$phone = new CmsPhonenumber();
$phone->phonenumber = 100 + $i;
$user->addPhonenumber($phone);
}
$this->_em->persist($user);
$this->_em->flush();
$this->_em->clear();
$query = $this->_em->createQuery("select u from Doctrine\\Tests\\Models\\CMS\\CmsUser u where u.username='gblanco'");
$gblanco = $query->getSingleResult();
$this->_em->remove($gblanco);
$this->_em->flush();
$this->_em->clear();
$this->assertEquals(0, $this->_em->createQuery("select count(p.phonenumber) from Doctrine\\Tests\\Models\\CMS\\CmsPhonenumber p")->getSingleScalarResult());
$this->assertEquals(0, $this->_em->createQuery("select count(u.id) from Doctrine\\Tests\\Models\\CMS\\CmsUser u")->getSingleScalarResult());
}
示例12: testJoinedOneToManyNativeQueryWithRSMBuilder
public function testJoinedOneToManyNativeQueryWithRSMBuilder()
{
$user = new CmsUser;
$user->name = 'Roman';
$user->username = 'romanb';
$user->status = 'dev';
$phone = new CmsPhonenumber;
$phone->phonenumber = 424242;
$user->addPhonenumber($phone);
$this->_em->persist($user);
$this->_em->flush();
$this->_em->clear();
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u');
$rsm->addJoinedEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p', 'u', 'phonenumbers');
$query = $this->_em->createNativeQuery('SELECT u.*, p.* FROM cms_users u LEFT JOIN cms_phonenumbers p ON u.id = p.user_id WHERE username = ?', $rsm);
$query->setParameter(1, 'romanb');
$users = $query->getResult();
$this->assertEquals(1, count($users));
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]);
$this->assertEquals('Roman', $users[0]->name);
$this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $users[0]->getPhonenumbers());
$this->assertTrue($users[0]->getPhonenumbers()->isInitialized());
$this->assertEquals(1, count($users[0]->getPhonenumbers()));
$phones = $users[0]->getPhonenumbers();
$this->assertEquals(424242, $phones[0]->phonenumber);
$this->assertTrue($phones[0]->getUser() === $users[0]);
$this->_em->clear();
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p');
$query = $this->_em->createNativeQuery('SELECT p.* FROM cms_phonenumbers p WHERE p.phonenumber = ?', $rsm);
$query->setParameter(1, $phone->phonenumber);
$phone = $query->getSingleResult();
$this->assertNotNull($phone->getUser());
$this->assertEquals($user->name, $phone->getUser()->getName());
}
示例13: testCollectionValuedAssociationIdentityMapBehaviorWithRefresh
public function testCollectionValuedAssociationIdentityMapBehaviorWithRefresh()
{
$user = new CmsUser();
$user->status = 'dev';
$user->username = 'romanb';
$user->name = 'Roman B.';
$phone1 = new CmsPhonenumber();
$phone1->phonenumber = 123;
$phone2 = new CmsPhonenumber();
$phone2->phonenumber = 234;
$phone3 = new CmsPhonenumber();
$phone3->phonenumber = 345;
$user->addPhonenumber($phone1);
$user->addPhonenumber($phone2);
$user->addPhonenumber($phone3);
$this->_em->persist($user);
// cascaded to phone numbers
$this->_em->flush();
$this->assertEquals(3, count($user->getPhonenumbers()));
//external update to CmsAddress
$this->_em->getConnection()->executeUpdate('insert into cms_phonenumbers (phonenumber, user_id) VALUES (?,?)', array(999, $user->getId()));
//select
$q = $this->_em->createQuery('select u, p from Doctrine\\Tests\\Models\\CMS\\CmsUser u join u.phonenumbers p');
$user2 = $q->getSingleResult();
$this->assertSame($user, $user2);
// Should still be the same 3 phonenumbers
$this->assertEquals(3, count($user2->getPhonenumbers()));
// But we want to have this external change!
// Solution 1: refresh().
$this->_em->refresh($user2);
$this->assertSame($user, $user2);
// should still be the same, always from identity map
// Now the collection should be refreshed with correct count
$this->assertEquals(4, count($user2->getPhonenumbers()));
}
示例14: testMultipleJoinComponentsUsingLeftJoin
public function testMultipleJoinComponentsUsingLeftJoin()
{
$userA = new CmsUser();
$userA->name = 'Benjamin';
$userA->username = 'beberlei';
$userA->status = 'developer';
$phonenumberA = new CmsPhonenumber();
$phonenumberA->phonenumber = '111111';
$userA->addPhonenumber($phonenumberA);
$userB = new CmsUser();
$userB->name = 'Alexander';
$userB->username = 'asm89';
$userB->status = 'developer';
$this->_em->persist($userA);
$this->_em->persist($userB);
$this->_em->flush();
$this->_em->clear();
$query = $this->_em->createQuery("\n SELECT u, p\n FROM Doctrine\\Tests\\Models\\CMS\\CmsUser u\n LEFT JOIN Doctrine\\Tests\\Models\\CMS\\CmsPhonenumber p WITH u = p.user\n ");
$users = $query->execute();
$this->assertEquals(4, count($users));
$this->assertInstanceOf('Doctrine\\Tests\\Models\\CMS\\CmsUser', $users[0]);
$this->assertInstanceOf('Doctrine\\Tests\\Models\\CMS\\CmsPhonenumber', $users[1]);
$this->assertInstanceOf('Doctrine\\Tests\\Models\\CMS\\CmsUser', $users[2]);
$this->assertNull($users[3]);
}
示例15: loadFixture
private function loadFixture()
{
$user = new CmsUser();
$user->name = 'Roman';
$user->username = 'romanb';
$user->status = 'developer';
$address = new CmsAddress();
$address->country = 'Germany';
$address->city = 'Berlin';
$address->zip = '12345';
$user->setAddress($address);
$email = new CmsEmail();
$email->setEmail('roman@domain.com');
$user->setEmail($email);
$ph1 = new CmsPhonenumber();
$ph1->phonenumber = "0301234";
$ph2 = new CmsPhonenumber();
$ph2->phonenumber = "987654321";
$user->addPhonenumber($ph1);
$user->addPhonenumber($ph2);
$this->_em->persist($user);
$this->_em->flush();
$this->userId = $user->getId();
$this->_em->clear();
}