public function testDelete()
 {
     $comment = m::mock(Comment::class);
     $this->commentRepository->shouldReceive('getById')->with(self::COMMENT_ID)->andReturn($comment);
     $this->commentRepository->shouldReceive('remove')->with($comment)->once();
     $this->deleteCommentHandler->delete(self::COMMENT_ID);
 }
 public function delete(int $id)
 {
     $comment = $this->commentRepository->getById($id);
     if (null === $comment) {
         throw new NotFoundHttpException();
     }
     $this->commentRepository->remove($comment);
 }
 public function create(Dto $commentDto) : Dto
 {
     /** @var Comment $comment */
     $comment = $this->dtoToEntityMapper->transform($commentDto);
     $this->commentRepository->add($comment);
     $this->systemWideEventDispatcher->dispatch(new CommentHasBeenAdded($comment->getAuthorsUsername(), $comment->getPostId()));
     foreach ($comment->getMentions() as $mention) {
         $this->systemWideEventDispatcher->dispatch(new UserHasBeenMentioned($comment->getAuthorsUsername(), $mention->getUsername(), $comment->getPostId()));
     }
     return $this->entityToDtoMapper->transform($comment);
 }
 public function testCreate()
 {
     $this->dtoToEntityMapper->shouldReceive('transform')->once()->andReturn($this->comment);
     $this->commentRepository->shouldReceive('add')->once()->withArgs([$this->comment]);
     $this->eventDispatcher->shouldReceive('dispatch');
     $this->entityToDtoMapper->shouldReceive('transform')->once()->withArgs([$this->comment])->andReturn($this->commentDto);
     $this->mention->shouldReceive('getUsername')->andReturn('mentioned_user');
     $this->comment->shouldReceive('getAuthorsUsername')->andReturn('test');
     $this->comment->shouldReceive('getAuthorsAvatarFilename')->andReturn('test.jpg');
     $this->comment->shouldReceive('getPostId')->andReturn(123);
     $this->comment->shouldReceive('getMentions')->andReturn(new ArrayCollection([$this->mention]));
     $createdCommentDto = $this->createCommentHandler->create($this->commentDto);
     $this->assertInstanceOf(CommentDto::class, $createdCommentDto);
 }
 public function listAction(int $postId) : JsonResponse
 {
     $comments = $this->commentRepository->getCommentsByPostId($postId);
     $dtoComments = $this->commentsMapper->transformCollection($comments);
     return $this->responseFactory->makeResponse($dtoComments);
 }