Esempio n. 1
0
 public function testJoinQueries()
 {
     $user = new CmsUser();
     $user->name = 'Guilherme';
     $user->username = '******';
     $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);
 }
Esempio n. 2
0
 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 = '******';
     $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 = '******';
     $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);
 }
 /**
  * @expectedException Doctrine\ORM\NonUniqueResultException
  */
 public function testGetSingleScalarResultThrowsExceptionOnNonUniqueResult()
 {
     $user = new CmsUser();
     $user->name = 'Guilherme';
     $user->username = '******';
     $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();
     $this->_em->createQuery("select a from Doctrine\\Tests\\Models\\CMS\\CmsArticle a")->getSingleScalarResult();
 }
Esempio n. 4
0
 /**
  * @group DDC-1278
  */
 public function testClearWithEntityName()
 {
     $user = new CmsUser();
     $user->name = 'Dominik';
     $user->username = '******';
     $user->status = 'developer';
     $address = new CmsAddress();
     $address->city = "Springfield";
     $address->zip = "12354";
     $address->country = "Germany";
     $address->street = "Foo Street";
     $address->user = $user;
     $user->address = $address;
     $article1 = new CmsArticle();
     $article1->topic = 'Foo';
     $article1->text = 'Foo Text';
     $article2 = new CmsArticle();
     $article2->topic = 'Bar';
     $article2->text = 'Bar Text';
     $user->addArticle($article1);
     $user->addArticle($article2);
     $this->_em->persist($article1);
     $this->_em->persist($article2);
     $this->_em->persist($address);
     $this->_em->persist($user);
     $this->_em->flush();
     $unitOfWork = $this->_em->getUnitOfWork();
     $this->_em->clear('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_DETACHED, $unitOfWork->getEntityState($user));
     $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $unitOfWork->getEntityState($address));
     $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $unitOfWork->getEntityState($article1));
     $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $unitOfWork->getEntityState($article2));
     $this->_em->clear();
     $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_DETACHED, $unitOfWork->getEntityState($address));
 }