public function testSerializeUnserializeModifyMerge()
 {
     $user = new CmsUser();
     $user->name = 'Guilherme';
     $user->username = '******';
     $user->status = 'developer';
     $ph1 = new CmsPhonenumber();
     $ph1->phonenumber = 1234;
     $user->addPhonenumber($ph1);
     $this->dm->persist($user);
     $this->dm->flush();
     $this->assertTrue($this->dm->contains($user));
     $this->assertTrue($user->phonenumbers->isInitialized());
     $serialized = serialize($user);
     $this->dm->clear();
     $this->assertFalse($this->dm->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->dm->contains($user));
     $this->dm->persist($ph2);
     // Merge back in
     $user = $this->dm->merge($user);
     // merge cascaded to phonenumbers
     $this->dm->flush();
     $this->assertTrue($this->dm->contains($user));
     $this->assertEquals(2, count($user->getPhonenumbers()));
     $phonenumbers = $user->getPhonenumbers();
     $this->assertTrue($this->dm->contains($phonenumbers[0]));
     $this->assertTrue($this->dm->contains($phonenumbers[1]));
 }
Exemplo n.º 2
0
 public function setUser(CmsUser $user)
 {
     if ($this->user !== $user) {
         $this->user = $user;
         $user->setAddress($this);
     }
 }
 public function setUp()
 {
     parent::setUp();
     $user1 = new CmsUser();
     $user1->username = "******";
     $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 = "******";
     $user2->name = "Roman";
     $user2->status = "active";
     $this->dm->persist($user1);
     $this->dm->persist($user2);
     $this->dm->persist($group1);
     $this->dm->persist($group2);
     $this->dm->flush();
     $this->dm->clear();
     $this->user1 = $this->dm->find(get_class($user1), $user1->id);
     $this->user2 = $this->dm->find(get_class($user1), $user2->id);
 }
Exemplo n.º 4
0
 /**
  * [jwage: Memory increased by 14.09 kb]
  */
 public function testMemoryUsage()
 {
     $memoryUsage = array();
     for ($i = 0; $i < 100; $i++) {
         $ph1 = new CmsPhonenumber();
         $ph1->phonenumber = '12345';
         $ph2 = new CmsPhonenumber();
         $ph2->phonenumber = '12346';
         $user = new CmsUser();
         $user->username = '******';
         $user->addPhonenumber($ph1);
         $user->addPhonenumber($ph2);
         $this->dm->persist($user);
         $this->dm->flush();
         $this->dm->clear();
         gc_collect_cycles();
         $memoryUsage[] = memory_get_usage();
     }
     $start = current($memoryUsage);
     $end = end($memoryUsage);
     $increase = $end - $start;
     echo sprintf('Memory increased by %s', $this->formatMemory($increase)) . PHP_EOL;
 }