/** * Test VotePackage. * * @dataProvider dataVotes */ public function testVotes($nbVotesUp, $nbVotesDown, $nbVotes) { $votes = []; for ($i = 0; $i < $nbVotesDown; ++$i) { $vote = $this->prophesize('Elcodi\\Component\\Comment\\Entity\\Interfaces\\VoteInterface'); $vote->getType()->willReturn(Vote::DOWN); $votes[] = $vote->reveal(); } for ($i = 0; $i < $nbVotesUp; ++$i) { $vote = $this->prophesize('Elcodi\\Component\\Comment\\Entity\\Interfaces\\VoteInterface'); $vote->getType()->willReturn(Vote::UP); $votes[] = $vote->reveal(); } $votePackage = VotePackage::create($votes); $this->assertEquals($nbVotesDown, $votePackage->getNbDownVotes()); $this->assertEquals($nbVotesUp, $votePackage->getNbUpVotes()); $this->assertEquals($nbVotes, $votePackage->getNbVotes()); }
/** * Create structure for comment * * @param CommentInterface $comment Comment * @param VotePackage $commentVotePackage Vote package * * @return array */ public function createCommentStructure(CommentInterface $comment, VotePackage $commentVotePackage = null) { $commentStructure = ['id' => $comment->getId(), 'authorName' => $comment->getAuthorName(), 'authorEmail' => $comment->getAuthorEmail(), 'content' => $comment->getContent(), 'context' => $comment->getContext(), 'createdAt' => $comment->getCreatedAt()->format('Y-m-d H:i:s'), 'updatedAt' => $comment->getUpdatedAt()->format('Y-m-d H:i:s')]; if ($commentVotePackage instanceof VotePackage) { $commentStructure = array_merge($commentStructure, ['nbVotes' => $commentVotePackage->getNbVotes(), 'nbUpVotes' => $commentVotePackage->getNbUpVotes(), 'nbDownVotes' => $commentVotePackage->getNbDownVotes()]); } return $commentStructure; }
/** * Get comment votes * * @param CommentInterface $comment Comment * * @return VotePackage Vote package */ public function getCommentVotes(CommentInterface $comment) { /** * @var VoteInterface[] $votes */ $votes = $this->commentVoteObjectDirector->findBy(['comment' => $comment]); return VotePackage::create($votes); }