Esempio n. 1
0
 public function testSetComments()
 {
     $post = new Post();
     $post->setTitle('Third post');
     $post->setContent('This is content');
     $c1 = new Comment();
     $c1->setContent('Like it');
     $this->em->persist($c1);
     $post->addComment($c1);
     $this->em->persist($post);
     $this->assertEquals(1, count($post->getComments()), 'Post has 1 comment');
     $comments = new ArrayCollection();
     for ($i = 0; $i < 5; $i++) {
         $comments[$i] = new Comment();
         $comments[$i]->setContent('Like it');
         $this->em->persist($comments[$i]);
     }
     $post->setComments($comments);
     $this->em->persist($post);
     $this->assertEquals(5, count($post->getComments()), 'Post has 5 comments, not 6 as the collection is overridden');
 }
Esempio n. 2
0
 public function testTree()
 {
     $c1 = new Comment();
     $c1->setContent('This is comment1');
     $this->em->persist($c1);
     $c2 = new Comment();
     $c2->setContent('This is comment2');
     $c2->setParent($c1);
     $this->em->persist($c2);
     $this->assertEquals($c1, $c2->getParent(), 'Parent comment match');
     $post = new Post();
     $post->setTitle('Commented post');
     $post->setContent('Content of the post');
     $this->em->persist($post);
     $c1->setPost($post);
     $this->em->persist($c1);
     $c3 = new Comment();
     $c3->setContent('This is comment3');
     $c3->setParent($c1);
     $this->em->persist($c3);
     $this->assertNull($c3->getPost(), 'Relation to Post does not propagate on children');
     $repository = $this->em->getRepository('Wurstpress\\CoreBundle\\Entity\\Comment');
     $this->em->flush();
     $this->assertEquals(2, $repository->childCount($c1, true), 'The number of direct replies to current comment should be 2');
     $this->assertEquals(2, $repository->childCount($c1), 'The number of all replies to current comment should be 2');
     $c4 = new Comment();
     $c4->setContent('This is comment4');
     $c4->setParent($c3);
     $this->em->persist($c4);
     $this->em->flush();
     $this->assertEquals(2, $repository->childCount($c1, true), 'The number of direct replies to current comment should be 2');
     $this->assertEquals(3, $repository->childCount($c1), 'The number of all replies to current comment should be 3');
 }