php Doctrine-Tests-Models-CMS-CmsUser类(方法)实例源码

下面列出了php Doctrine-Tests-Models-CMS-CmsUser 类(方法)源码代码实例,从而了解它的用法。

作者:dracon    项目:forked-php-orm-benchmar   
public function testOrphanRemoval()
 {
     $user = new CmsUser();
     $user->status = 'dev';
     $user->username = 'romanb';
     $user->name = 'Roman B.';
     $address = new CmsAddress();
     $address->country = 'de';
     $address->zip = 1234;
     $address->city = 'Berlin';
     $user->setAddress($address);
     $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 a FROM Doctrine\\Tests\\Models\\CMS\\CmsAddress a');
     $result = $query->getResult();
     $this->assertEquals(0, count($result), 'CmsAddress should be removed by orphanRemoval');
 }

作者:andrei    项目:doctrin   
public function testManyToManyAddRemove()
 {
     // Set up user with 2 groups
     $user = new CmsUser();
     $user->username = 'romanb';
     $user->status = 'dev';
     $user->name = 'Roman B.';
     $group1 = new CmsGroup();
     $group1->name = 'Developers';
     $group2 = new CmsGroup();
     $group2->name = 'Humans';
     $user->addGroup($group1);
     $user->addGroup($group2);
     $this->_em->persist($user);
     // cascades to groups
     $this->_em->flush();
     $this->_em->clear();
     $uRep = $this->_em->getRepository(get_class($user));
     // Get user
     $user = $uRep->findOneById($user->getId());
     $this->assertFalse($user->getGroups()->isInitialized());
     // Check groups
     $this->assertEquals(2, $user->getGroups()->count());
     $this->assertTrue($user->getGroups()->isInitialized());
     // Remove first group
     unset($user->groups[0]);
     //$user->getGroups()->remove(0);
     $this->_em->flush();
     $this->_em->clear();
     // Reload same user
     $user2 = $uRep->findOneById($user->getId());
     // Check groups
     $this->assertEquals(1, $user2->getGroups()->count());
 }

作者:steffenbre    项目:phpcr-od   
public function setUser(CmsUser $user)
 {
     if ($this->user !== $user) {
         $this->user = $user;
         $user->setAddress($this);
     }
 }

作者:selimc    项目:servigase   
public function testIssue()
 {
     $phone = new CmsPhonenumber();
     $phone->phonenumber = "1234";
     // puts user and phone into commit order calculator
     $this->_em->persist($phone);
     $this->_em->flush();
     $address = new \Doctrine\Tests\Models\CMS\CmsAddress();
     $address->city = "bonn";
     $address->country = "Germany";
     $address->street = "somestreet!";
     $address->zip = 12345;
     $this->_em->persist($address);
     $user = new CmsUser();
     $user->username = "beberlei";
     $user->name = "benjamin";
     $user->status = "active";
     $user->setAddress($address);
     // puts user and address into commit order calculator, but does not calculate user dependencies new
     $this->_em->persist($user);
     $this->_em->flush();
     $this->_em->remove($user->getAddress());
     $this->_em->remove($user);
     $this->_em->flush();
 }

作者:jeffreiffer    项目:doctrine   
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]));
 }

作者:Herriniain    项目:iVarotr   
public function setUp()
 {
     $this->useModelSet('cms');
     parent::setUp();
     $user1 = new CmsUser();
     $user1->username = "beberlei";
     $user1->name = "Benjamin";
     $user1->status = "active";
     $group1 = new CmsGroup();
     $group1->name = "test";
     $group2 = new CmsGroup();
     $group2->name = "test";
     $user1->addGroup($group1);
     $user1->addGroup($group2);
     $user2 = new CmsUser();
     $user2->username = "romanb";
     $user2->name = "Roman";
     $user2->status = "active";
     $this->_em->persist($user1);
     $this->_em->persist($user2);
     $this->_em->persist($group1);
     $this->_em->persist($group2);
     $this->_em->flush();
     $this->_em->clear();
     $this->user1 = $this->_em->find(get_class($user1), $user1->id);
     $this->user2 = $this->_em->find(get_class($user1), $user2->id);
 }

作者:andrei    项目:doctrin   
public function testJoinQueries()
 {
     $user = new CmsUser();
     $user->name = 'Guilherme';
     $user->username = 'gblanco';
     $user->status = 'developer';
     $article1 = new CmsArticle();
     $article1->topic = "Doctrine 2";
     $article1->text = "This is an introduction to Doctrine 2.";
     $user->addArticle($article1);
     $article2 = new CmsArticle();
     $article2->topic = "Symfony 2";
     $article2->text = "This is an introduction to Symfony 2.";
     $user->addArticle($article2);
     $this->_em->persist($user);
     $this->_em->persist($article1);
     $this->_em->persist($article2);
     $this->_em->flush();
     $this->_em->clear();
     $query = $this->_em->createQuery("select u, a from Doctrine\\Tests\\Models\\CMS\\CmsUser u join u.articles a");
     $users = $query->getResult();
     $this->assertEquals(1, count($users));
     $this->assertTrue($users[0] instanceof CmsUser);
     $this->assertEquals(2, count($users[0]->articles));
     $this->assertEquals('Doctrine 2', $users[0]->articles[0]->topic);
     $this->assertEquals('Symfony 2', $users[0]->articles[1]->topic);
 }

作者:selimc    项目:servigase   
/**
  * @return CmsUser
  */
 private function createNewValidUser()
 {
     $user = new CmsUser();
     $user->username = 'fran6co';
     $user->name = 'Francisco Facioni';
     $group = new CmsGroup();
     $group->name = "users";
     $user->addGroup($group);
     return $user;
 }

作者:naderma    项目:doctrine   
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.");
    }

作者:relo-sa    项目:doctrine   
public function buildUser($name, $username, $status, $address)
 {
     $user = new CmsUser();
     $user->name = $name;
     $user->username = $username;
     $user->status = $status;
     $user->setAddress($address);
     $this->_em->persist($user);
     $this->_em->flush();
     return $user;
 }

作者:selimc    项目:servigase   
/**
  * Verifying that proxies can be used without problems as query parameters
  */
 public function testFindWithProxyName()
 {
     $result = $this->_em->find('Doctrine\\Tests\\Proxies\\__CG__\\Doctrine\\Tests\\Models\\CMS\\CmsUser', $this->user->getId());
     $this->assertSame($this->user->getId(), $result->getId());
     $this->_em->clear();
     $result = $this->_em->getReference('Doctrine\\Tests\\Proxies\\__CG__\\Doctrine\\Tests\\Models\\CMS\\CmsUser', $this->user->getId());
     $this->assertSame($this->user->getId(), $result->getId());
     $this->_em->clear();
     $result = $this->_em->getRepository('Doctrine\\Tests\\Proxies\\__CG__\\Doctrine\\Tests\\Models\\CMS\\CmsUser')->findOneBy(array('username' => $this->user->username));
     $this->assertSame($this->user->getId(), $result->getId());
     $this->_em->clear();
     $result = $this->_em->createQuery('SELECT u FROM Doctrine\\Tests\\Proxies\\__CG__\\Doctrine\\Tests\\Models\\CMS\\CmsUser u WHERE u.id = ?1')->setParameter(1, $this->user->getId())->getSingleResult();
     $this->assertSame($this->user->getId(), $result->getId());
     $this->_em->clear();
 }

作者:Herriniain    项目:iVarotr   
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();
 }

作者:Herriniain    项目:iVarotr   
public function testGivenOrphanRemovalOneToOne_WhenReplacing_ThenNoUniqueConstraintError()
 {
     $user = new CmsUser();
     $user->name = "Benjamin";
     $user->username = "beberlei";
     $user->status = "something";
     $user->setEmail($email = new CmsEmail());
     $email->setEmail("kontakt@beberlei.de");
     $this->_em->persist($user);
     $this->_em->flush();
     $this->assertTrue($this->_em->contains($email));
     $user->setEmail($newEmail = new CmsEmail());
     $newEmail->setEmail("benjamin.eberlei@googlemail.com");
     $this->_em->flush();
     $this->assertFalse($this->_em->contains($email));
 }

作者:Herriniain    项目:iVarotr   
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;
 }

作者:Herriniain    项目:iVarotr   
public function testIssue()
 {
     $em = $this->_em;
     $uow = $em->getUnitOfWork();
     $originalArticle = new CmsArticle();
     $originalUser = new CmsUser();
     $originalArticle->topic = 'Unit Test';
     $originalArticle->text = 'How to write a test';
     $originalUser->name = 'Doctrine Bot';
     $originalUser->username = 'DoctrineBot';
     $originalUser->status = 'active';
     $originalUser->addArticle($originalArticle);
     $em->persist($originalUser);
     $em->persist($originalArticle);
     $em->flush();
     $em->clear();
     $article = $em->find('Doctrine\\Tests\\Models\\CMS\\CmsArticle', $originalArticle->id);
     $user = new CmsUser();
     $user->name = 'Doctrine Bot 2.0';
     $user->username = 'BotDoctrine2';
     $user->status = 'new';
     $article->setAuthor($user);
     $this->assertEquals(UnitOfWork::STATE_DETACHED, $uow->getEntityState($originalArticle));
     $this->assertEquals(UnitOfWork::STATE_DETACHED, $uow->getEntityState($originalUser));
     $this->assertEquals(UnitOfWork::STATE_MANAGED, $uow->getEntityState($article));
     $this->assertEquals(UnitOfWork::STATE_NEW, $uow->getEntityState($user));
     $em->detach($user);
     $em->detach($article);
     $userMerged = $em->merge($user);
     $articleMerged = $em->merge($article);
     $this->assertEquals(UnitOfWork::STATE_NEW, $uow->getEntityState($user));
     $this->assertEquals(UnitOfWork::STATE_DETACHED, $uow->getEntityState($article));
     $this->assertEquals(UnitOfWork::STATE_MANAGED, $uow->getEntityState($userMerged));
     $this->assertEquals(UnitOfWork::STATE_MANAGED, $uow->getEntityState($articleMerged));
     $this->assertNotSame($user, $userMerged);
     $this->assertNotSame($article, $articleMerged);
     $this->assertNotSame($userMerged, $articleMerged->user);
     $this->assertSame($user, $articleMerged->user);
 }

作者:nckin    项目:doctrine   
public function testOrphanRemovalWhenUnlink()
 {
     $user = new CmsUser();
     $user->status = 'dev';
     $user->username = 'beberlei';
     $user->name = 'Bejamin Eberlei';
     $email = new CmsEmail();
     $email->email = 'beberlei@domain.com';
     $user->setEmail($email);
     $this->_em->persist($user);
     $this->_em->flush();
     $userId = $user->getId();
     $this->_em->clear();
     $user = $this->_em->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', $userId);
     $user->setEmail(null);
     $this->_em->persist($user);
     $this->_em->flush();
     $this->_em->clear();
     $query = $this->_em->createQuery('SELECT e FROM Doctrine\\Tests\\Models\\CMS\\CmsEmail e');
     $result = $query->getResult();
     $this->assertEquals(0, count($result), 'CmsEmail should be removed by orphanRemoval');
 }

作者:selimc    项目:servigase   
/**
  * @group DDC-767
  */
 public function testCollectionChangesInsideTransaction()
 {
     $user = new CmsUser();
     $user->name = "beberlei";
     $user->status = "active";
     $user->username = "beberlei";
     $group1 = new CmsGroup();
     $group1->name = "foo";
     $group2 = new CmsGroup();
     $group2->name = "bar";
     $group3 = new CmsGroup();
     $group3->name = "baz";
     $user->addGroup($group1);
     $user->addGroup($group2);
     $this->_em->persist($user);
     $this->_em->persist($group1);
     $this->_em->persist($group2);
     $this->_em->persist($group3);
     $this->_em->flush();
     $this->_em->clear();
     /* @var $pUser CmsUser */
     $pUser = $this->_em->find(get_class($user), $user->id);
     $this->assertNotNull($pUser, "User not retrieved from database.");
     $groups = array($group2->id, $group3->id);
     try {
         $this->_em->beginTransaction();
         $pUser->groups->clear();
         $this->_em->flush();
         // Add new
         foreach ($groups as $groupId) {
             $pUser->addGroup($this->_em->find(get_class($group1), $groupId));
         }
         $this->_em->flush();
         $this->_em->commit();
     } catch (\Exception $e) {
         $this->_em->rollback();
     }
 }

作者:dracon    项目:forked-php-orm-benchmar   
public function testJoinedOneToOneNativeQuery()
 {
     $user = new CmsUser();
     $user->name = 'Roman';
     $user->username = 'romanb';
     $user->status = 'dev';
     $addr = new CmsAddress();
     $addr->country = 'germany';
     $addr->zip = 10827;
     $addr->city = 'Berlin';
     $user->setAddress($addr);
     $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\\CmsAddress', 'a', 'u', 'address');
     $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('a_id'), 'id');
     $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('country'), 'country');
     $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('zip'), 'zip');
     $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('city'), 'city');
     $query = $this->_em->createNativeQuery('SELECT u.id, u.name, u.status, a.id AS a_id, a.country, a.zip, a.city FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.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->assertFalse($users[0]->getPhonenumbers()->isInitialized());
     $this->assertTrue($users[0]->getAddress() instanceof CmsAddress);
     $this->assertTrue($users[0]->getAddress()->getUser() == $users[0]);
     $this->assertEquals('germany', $users[0]->getAddress()->getCountry());
     $this->assertEquals(10827, $users[0]->getAddress()->getZipCode());
     $this->assertEquals('Berlin', $users[0]->getAddress()->getCity());
 }

作者:doctrin    项目:phpcr-od   
public function benchPersistMany()
 {
     $parent1 = new ParentTestObj();
     $parent1->nodename = "root1";
     $parent1->name = "root1";
     $parent1->setParentDocument($this->root);
     $parent2 = new ParentTestObj();
     $parent2->name = "/root2";
     $parent2->nodename = "root2";
     $parent2->setParentDocument($this->root);
     $child = new ParentNoNodeNameTestObj();
     $child->setParentDocument($parent1);
     $child->name = "child";
     $c1 = new Comment();
     $c1->name = 'c1';
     $c1->parent = $this->root;
     $c1->setText('deutsch');
     $group1 = new \Doctrine\Tests\Models\CMS\CmsGroup();
     $group1->name = "Test!";
     $group1->id = '/functional/group1';
     $group2 = new \Doctrine\Tests\Models\CMS\CmsGroup();
     $group2->name = "Test!";
     $group2->id = '/functional/group2';
     $user = new \Doctrine\Tests\Models\CMS\CmsUser();
     $user->username = "beberlei";
     $user->name = "Benjamin";
     $user->addGroup($group1);
     $user->addGroup($group2);
     $this->documentManager->persist($parent1);
     $this->documentManager->persist($parent2);
     $this->documentManager->persist($child);
     $this->documentManager->persist($c1);
     $this->documentManager->persist($user);
     $this->documentManager->persist($group1);
     $this->documentManager->persist($group2);
     $this->documentManager->flush();
 }

作者:robertowes    项目:CuteFlow-V   
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');
 }


问题


面经


文章

微信
公众号

扫码关注公众号