public function testUseMultiplePositionalParameters() { $user = new CmsUser(); $user->name = "John Galt"; $user->username = "******"; $user->status = "inactive"; $article = new CmsArticle(); $article->topic = "This is John Galt speaking!"; $article->text = "Yadda Yadda!"; $article->setAuthor($user); $this->_em->persist($user); $this->_em->persist($article); $this->_em->flush(); $dql = "SELECT a FROM Doctrine\\Tests\\Models\\CMS\\CmsArticle a WHERE a.topic = ?1 AND a.user = ?2 AND a.user = ?3 AND a.text = ?4"; $farticle = $this->_em->createQuery($dql)->setParameter(1, 'This is John Galt speaking!')->setParameter(2, $user)->setParameter(3, $user)->setParameter(4, 'Yadda Yadda!')->getSingleResult(); $this->assertSame($article, $farticle); }
public function testRefreshWithManyToOne() { $user = new CmsUser(); $user->name = "beberlei"; $user->status = "active"; $user->username = "******"; $article = new CmsArticle(); $article->setAuthor($user); $article->text = "foo"; $article->topic = "bar"; $this->_em->persist($user); $this->_em->persist($article); $this->_em->flush(); $this->assertType('Doctrine\\Common\\Collections\\Collection', $user->articles); $this->_em->refresh($article); $this->assertTrue($article !== $user->articles, "The article should not be replaced on the inverse side of the relation."); $this->assertType('Doctrine\\Common\\Collections\\Collection', $user->articles); }
private function loadFixtureData() { $user = new CmsUser(); $user->name = 'Roman'; $user->username = '******'; $user->status = 'developer'; $address = new CmsAddress(); $address->country = 'Germany'; $address->city = 'Berlin'; $address->zip = '12345'; $user->address = $address; // inverse side $address->user = $user; // owning side! $group = new CmsGroup(); $group->name = 'foo_group'; $user->addGroup($group); $article1 = new CmsArticle(); $article1->topic = "Test1"; $article1->text = "Test"; $article1->setAuthor($user); $article2 = new CmsArticle(); $article2->topic = "Test2"; $article2->text = "Test"; $article2->setAuthor($user); $this->_em->persist($article1); $this->_em->persist($article2); $this->_em->persist($user); $user2 = new CmsUser(); $user2->name = 'Guilherme'; $user2->username = '******'; $user2->status = 'developer'; $address2 = new CmsAddress(); $address2->country = 'France'; $address2->city = 'Paris'; $address2->zip = '12345'; $user->address = $address2; // inverse side $address2->user = $user2; // owning side! $user2->addGroup($group); $group2 = new CmsGroup(); $group2->name = 'bar_group'; $user2->addGroup($group2); $this->_em->persist($user2); $this->_em->flush(); $this->_em->clear(); $this->userId = $user->getId(); $this->userId2 = $user2->getId(); $this->articleId = $article1->id; $this->articleId2 = $article2->id; $this->groupId = $group->id; $this->groupId2 = $group2->id; }
public function addArticle(CmsArticle $article) { $this->articles[] = $article; $article->setAuthor($this); }
/** * @group DDC-600 * @group DDC-455 */ public function testNewAssociatedEntityDuringFlushThrowsException3() { //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $art = new CmsArticle(); $art->topic = 'topic'; $art->text = 'the text'; $com = new CmsComment(); $com->topic = 'Good'; $com->text = 'Really good!'; $art->addComment($com); $this->_em->persist($art); // pretend we forgot to persist $com try { $this->_em->flush(); // should raise an exception $this->fail(); } catch (\InvalidArgumentException $expected) { } }
public function testFlushDoesNotIssueUnnecessaryUpdates() { $user = new CmsUser(); $user->name = 'Guilherme'; $user->username = '******'; $user->status = 'developer'; $address = new CmsAddress(); $address->country = 'Germany'; $address->city = 'Berlin'; $address->zip = '12345'; $address->user = $user; $user->address = $address; $article = new \Doctrine\Tests\Models\CMS\CmsArticle(); $article->text = "Lorem ipsum dolor sunt."; $article->topic = "A Test Article!"; $article->setAuthor($user); $this->_em->persist($article); $this->_em->persist($user); //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $this->_em->flush(); $this->_em->clear(); $query = $this->_em->createQuery('select u,a,ad from Doctrine\\Tests\\Models\\CMS\\CmsUser u join u.articles a join u.address ad'); $user2 = $query->getSingleResult(); $this->assertEquals(1, count($user2->articles)); $this->assertTrue($user2->address instanceof CmsAddress); $oldLogger = $this->_em->getConnection()->getConfiguration()->getSQLLogger(); $debugStack = new \Doctrine\DBAL\Logging\DebugStack(); $this->_em->getConnection()->getConfiguration()->setSQLLogger($debugStack); $this->_em->flush(); $this->assertEquals(0, count($debugStack->queries)); $this->_em->getConnection()->getConfiguration()->setSQLLogger($oldLogger); }
public function populate() { $groups = array(); for ($j = 0; $j < 3; $j++) { $group = new CmsGroup(); $group->name = "group{$j}"; $groups[] = $group; $this->_em->persist($group); } for ($i = 0; $i < 9; $i++) { $user = new CmsUser(); $user->name = "Name{$i}"; $user->username = "******"; $user->status = "active"; $user->email = new CmsEmail(); $user->email->user = $user; $user->email->email = "email{$i}"; for ($j = 0; $j < 3; $j++) { $user->addGroup($groups[$j]); } $this->_em->persist($user); for ($j = 0; $j < $i + 1; $j++) { $article = new CmsArticle(); $article->topic = "topic{$i}{$j}"; $article->text = "text{$i}{$j}"; $article->setAuthor($user); $article->version = 0; $this->_em->persist($article); } } for ($i = 0; $i < 9; $i++) { $company = new Company(); $company->name = "name{$i}"; $company->logo = new Logo(); $company->logo->image = "image{$i}"; $company->logo->image_width = 100 + $i; $company->logo->image_height = 100 + $i; $company->logo->company = $company; for ($j = 0; $j < 3; $j++) { $department = new Department(); $department->name = "name{$i}{$j}"; $department->company = $company; $company->departments[] = $department; } $this->_em->persist($company); } for ($i = 0; $i < 9; $i++) { $user = new User1(); $user->name = "name{$i}"; $user->email = "email{$i}"; $this->_em->persist($user); } $manager = new CompanyManager(); $manager->setName('Roman B.'); $manager->setTitle('Foo'); $manager->setDepartment('IT'); $manager->setSalary(100000); $this->_em->persist($manager); $this->_em->flush(); }