public function testOrphanRemoval()
 {
     $user = new CmsUser();
     $user->status = 'dev';
     $user->username = '******';
     $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');
 }
Пример #2
0
 public function testBasicIdentityManagement()
 {
     $user = new CmsUser();
     $user->status = 'dev';
     $user->username = '******';
     $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();
     $this->_em->clear();
     $user2 = $this->_em->find(get_class($user), $user->getId());
     $this->assertTrue($user2 !== $user);
     $user3 = $this->_em->find(get_class($user), $user->getId());
     $this->assertTrue($user2 === $user3);
     $address2 = $this->_em->find(get_class($address), $address->getId());
     $this->assertTrue($address2 !== $address);
     $address3 = $this->_em->find(get_class($address), $address->getId());
     $this->assertTrue($address2 === $address3);
     $this->assertTrue($user2->getAddress() === $address2);
     // !!!
 }
Пример #3
0
 public function setUser(CmsUser $user)
 {
     if ($this->user !== $user) {
         $this->user = $user;
         $user->setAddress($this);
     }
 }
Пример #4
0
 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 = "******";
     $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();
 }
Пример #5
0
 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;
 }
Пример #6
0
 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 = '******';
     $u1->status = 'developer';
     $u1->email->email = '*****@*****.**';
     $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 = '******';
     $u2->status = 'developer';
     $u2->email->email = '*****@*****.**';
     $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 = '******';
     $u3->status = 'developer';
     $u3->email->email = '*****@*****.**';
     $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);
 }
 public function testJoinedOneToOneNativeQuery()
 {
     $user = new CmsUser();
     $user->name = 'Roman';
     $user->username = '******';
     $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());
 }
Пример #8
0
 public function loadAssociatedFixture()
 {
     $address = new CmsAddress();
     $address->city = "Berlin";
     $address->country = "Germany";
     $address->street = "Foostreet";
     $address->zip = "12345";
     $user = new CmsUser();
     $user->name = 'Roman';
     $user->username = '******';
     $user->status = 'freak';
     $user->setAddress($address);
     $this->_em->persist($user);
     $this->_em->persist($address);
     $this->_em->flush();
     $this->_em->clear();
     return array($user->id, $address->id);
 }
Пример #9
0
 /**
  * @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 = '******';
     $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']);
 }
 public function testQueryEntityByReference()
 {
     $user = new CmsUser();
     $user->name = 'Guilherme';
     $user->username = '******';
     $user->status = 'developer';
     $address = new CmsAddress();
     $address->country = 'Germany';
     $address->city = 'Berlin';
     $address->zip = '12345';
     $user->setAddress($address);
     $this->_em->transactional(function ($em) use($user) {
         $em->persist($user);
     });
     $this->_em->clear();
     //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
     $userRef = $this->_em->getReference('Doctrine\\Tests\\Models\\CMS\\CmsUser', $user->getId());
     $address2 = $this->_em->createQuery('select a from Doctrine\\Tests\\Models\\CMS\\CmsAddress a where a.user = :user')->setParameter('user', $userRef)->getSingleResult();
     $this->assertTrue($address2->getUser() instanceof \Doctrine\ORM\Proxy\Proxy);
     $this->assertTrue($userRef === $address2->getUser());
     $this->assertFalse($userRef->__isInitialized__);
     $this->assertEquals('Germany', $address2->country);
     $this->assertEquals('Berlin', $address2->city);
     $this->assertEquals('12345', $address2->zip);
 }
Пример #11
0
    public function testJoinedOneToOneNativeQueryWithRSMBuilder()
    {
        $user = new CmsUser;
        $user->name = 'Roman';
        $user->username = '******';
        $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 ResultSetMappingBuilder($this->_em);
        $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u');
        $rsm->addJoinedEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', 'a', 'u', 'address', array('id' => 'a_id'));

        $query = $this->_em->createNativeQuery('SELECT u.*, a.*, a.id AS a_id 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->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]);
        $this->assertEquals('Roman', $users[0]->name);
        $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $users[0]->getPhonenumbers());
        $this->assertFalse($users[0]->getPhonenumbers()->isInitialized());
        $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $users[0]->getAddress());
        $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());

        $this->_em->clear();

        $rsm = new ResultSetMappingBuilder($this->_em);
        $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', 'a');
        $query = $this->_em->createNativeQuery('SELECT a.* FROM cms_addresses a WHERE a.id = ?', $rsm);
        $query->setParameter(1, $addr->getId());
        $address = $query->getSingleResult();

        $this->assertNotNull($address->getUser());
        $this->assertEquals($user->name, $address->getUser()->getName());
    }
Пример #12
0
 private function loadFixture()
 {
     $user = new CmsUser();
     $user->name = 'Roman';
     $user->username = '******';
     $user->status = 'developer';
     $address = new CmsAddress();
     $address->country = 'Germany';
     $address->city = 'Berlin';
     $address->zip = '12345';
     $user->setAddress($address);
     $email = new CmsEmail();
     $email->setEmail('*****@*****.**');
     $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();
 }