public function testOneToOne() { $date1 = new DateTime(); $date1->setTimestamp(strtotime('-20 seconds')); $date2 = new DateTime(); $date2->setTimestamp(strtotime('-10 seconds')); $blogPost = new \Documents\BlogPost('Test'); $blogPost->addComment(new \Documents\Comment('Comment 1', $date1)); $blogPost->addComment(new \Documents\Comment('Comment 2', $date2)); $this->dm->persist($blogPost); $this->dm->flush(); $this->dm->clear(); $blogPost = $this->dm->createQueryBuilder('Documents\\BlogPost')->getQuery()->getSingleResult(); $this->assertEquals('Comment 2', $blogPost->repoComment->getText()); $this->assertEquals('Comment 1', $blogPost->repoComments[0]->getText()); $this->assertEquals('Comment 2', $blogPost->repoComments[1]->getText()); }
public function testFilterCrieriaShouldAndWithMappingCriteriaOwningSide() { $blogPost = new \Documents\BlogPost('Roger'); $blogPost->addComment(new \Documents\Comment('comment by normal user', new \DateTime(), false)); $blogPost->addComment(new \Documents\Comment('comment by admin', new \DateTime(), true)); $this->dm->persist($blogPost); $this->dm->flush(); $this->dm->clear(); $filterCollection = $this->dm->getFilterCollection(); $filterCollection->enable('testFilter'); $testFilter = $filterCollection->getFilter('testFilter'); $testFilter->setParameter('class', 'Documents\\Comment'); $testFilter->setParameter('field', 'isByAdmin'); $testFilter->setParameter('value', false); $blogPost = $this->dm->getRepository('Documents\\BlogPost')->find($blogPost->id); // Admin comments should be removed by the filter $this->assertCount(1, $blogPost->comments); /* Admin comments should be removed by the filter, and user comments * should be removed by the mapping criteria. */ $this->assertCount(0, $blogPost->adminComments); }
private function insertTestData() { $baseballTag = new \Documents\Tag('baseball'); $footballTag = new \Documents\Tag('football'); $blogPost = new \Documents\BlogPost(); $blogPost->name = 'Test 1'; $blogPost->addTag($baseballTag); $this->dm->persist($blogPost); $blogPost = new \Documents\BlogPost(); $blogPost->name = 'Test 2'; $blogPost->addTag($baseballTag); $this->dm->persist($blogPost); $blogPost = new \Documents\BlogPost(); $blogPost->name = 'Test 3'; $blogPost->addTag($footballTag); $this->dm->persist($blogPost); $blogPost = new \Documents\BlogPost(); $blogPost->name = 'Test 4'; $blogPost->addTag($baseballTag); $blogPost->addTag($footballTag); $this->dm->persist($blogPost); $this->dm->flush(); $this->dm->clear(); }
public function testSortLimitAndSkipReferences() { $date1 = new DateTime(); $date1->setTimestamp(strtotime('-20 seconds')); $date2 = new DateTime(); $date2->setTimestamp(strtotime('-10 seconds')); $blogPost = new \Documents\BlogPost('Test'); $blogPost->addComment(new \Documents\Comment('Comment 1', $date1)); $blogPost->addComment(new \Documents\Comment('Comment 2', $date2)); $this->dm->persist($blogPost); $this->dm->flush(); $this->dm->clear(); $blogPost = $this->dm->createQueryBuilder('Documents\\BlogPost')->getQuery()->getSingleResult(); $this->assertEquals('Comment 1', $blogPost->comments[0]->text); $this->assertEquals('Comment 2', $blogPost->comments[1]->text); $this->assertEquals('Test', $blogPost->comments[0]->parent->name); $this->assertEquals('Test', $blogPost->comments[1]->parent->name); $this->dm->clear(); $comment = $this->dm->createQueryBuilder('Documents\\Comment')->getQuery()->getSingleResult(); $this->assertEquals('Test', $comment->parent->getName()); $this->dm->clear(); $blogPost = $this->dm->createQueryBuilder('Documents\\BlogPost')->getQuery()->getSingleResult(); $this->assertEquals('Comment 1', $blogPost->firstComment->getText()); $this->assertEquals('Comment 2', $blogPost->latestComment->getText()); $this->assertEquals(2, count($blogPost->last5Comments)); $this->assertEquals('Comment 2', $blogPost->last5Comments[0]->getText()); $this->assertEquals('Comment 1', $blogPost->last5Comments[1]->getText()); $this->dm->clear(); $blogPost = $this->dm->createQueryBuilder('Documents\\BlogPost')->getQuery()->getSingleResult(); $blogPost->addComment(new \Documents\Comment('Comment 3 by admin', $date1, true)); $blogPost->addComment(new \Documents\Comment('Comment 4 by admin', $date2, true)); $this->dm->flush(); $this->dm->clear(); $blogPost = $this->dm->createQueryBuilder('Documents\\BlogPost')->getQuery()->getSingleResult(); $this->assertEquals(2, count($blogPost->adminComments)); $this->assertEquals('Comment 4 by admin', $blogPost->adminComments[0]->getText()); $this->assertEquals('Comment 3 by admin', $blogPost->adminComments[1]->getText()); }