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); }