RestBundle\Tests\Controller\RestControllerTest::testGetCommentsFromSpecificPost PHP Method

testGetCommentsFromSpecificPost() public method

    public function testGetCommentsFromSpecificPost()
    {
        $post = $this->getExamplePostEntity();
        $this->entityManager->persist($post);
        $this->entityManager->flush();
        $client = static::createClient();
        $client->request('GET', '/api/v1/comments/posts/' . $post->getId() . '.json');
        $this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode());
        $postComments = json_decode($client->getResponse()->getContent(), true);
        $this->assertCount(0, $postComments);
        $comment = $this->getExampleCommentEntity();
        $comment->setPost($post);
        $this->entityManager->persist($comment);
        $this->entityManager->flush();
        $client->request('GET', '/api/v1/comments/posts/' . $post->getId() . '.json');
        $this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode());
        $postComments = json_decode($client->getResponse()->getContent(), true);
        $this->assertCount(1, $postComments);
        $this->entityManager->remove($post);
        $this->entityManager->flush();
    }