Example #1
0
 public function testRemoveComment()
 {
     $post = new Post();
     $post->setTitle('Fourth post');
     $post->setContent('This is content');
     $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');
     $post->removeComment($comments[1]);
     $this->em->persist($post);
     $this->assertEquals(4, count($post->getComments()), 'Post has 4 comments');
 }