UserIncrementCommentCountWhenCommentPostedTest.php 3.08 KB
<?php

namespace FootyRoom\Tests\Integration\User;

use FootyRoom\Core\Comment\Author;
use FootyRoom\Core\Comment\Comment;
use FootyRoom\Core\Comment\CommentPosted;
use FootyRoom\Core\ForumPost\ForumPost;
use FootyRoom\Core\Wall\Wall;
use FootyRoom\Core\User\IncrementCommentCountWhenCommentPosted;
use FootyRoom\Repositories\UserRepository;
use FootyRoom\Tests\TestCase;

class UserIncrementCommentCountWhenCommentPostedTest extends TestCase
{
    public function setup()
    {
        $this->mockUserRepository = $this->getMockBuilder(UserRepository::class)
                            ->disableOriginalConstructor()
                            ->getMock();

        $this->incrementPostCountWhenForumPostPosted = new IncrementCommentCountWhenCommentPosted(
            $this->mockUserRepository
        );
    }

    public function testIncrementCommentCountWillNotBeCalledIfPostIsInstanceofWall()
    {
        $postId = 1;
        $author = new Author(41301, 'chanBC');
        $content = 'test content';
        $html = '';

        $comment = new Comment(
            $postId,
            $author,
            $content,
            $html
        );

        $userId = 41301;
        $username = 'Denis';

        $wall = new Wall(
            $userId,
            $username
        );

        $commentPosted = new CommentPosted($comment, $wall);

        $this->mockUserRepository->expects($this->never())
                                 ->method('incrementCommentCount');

        $this->incrementPostCountWhenForumPostPosted->handle($commentPosted);
    }

    public function testIncrementCommentCountWillNotBeCalledIfAuthorIsNotMember()
    {
        $postId = 1;
        $author = new Author('', 'chanBC');
        $content = 'test content';
        $html = '';

        $comment = new Comment(
            $postId,
            $author,
            $content,
            $html
        );

        $title = 'title';
        $categoryId = 61;
        $userId = '';

        $forumPost = new ForumPost(
            $title,
            $categoryId,
            $userId
        );

        $commentPosted = new CommentPosted($comment, $forumPost);

        $this->mockUserRepository->expects($this->never())
                                 ->method('incrementCommentCount');

        $this->incrementPostCountWhenForumPostPosted->handle($commentPosted);
    }

    public function testIncrementCommentCountWasCalled()
    {
        $postId = 1;
        $author = new Author(41301, 'chanBC');
        $content = 'test content';
        $html = '';

        $comment = new Comment(
            $postId,
            $author,
            $content,
            $html
        );

        $title = 'title';
        $categoryId = 61;
        $userId = 41301;

        $forumPost = new ForumPost(
            $title,
            $categoryId,
            $userId
        );

        $commentPosted = new CommentPosted($comment, $forumPost);

        $this->mockUserRepository->expects($this->once())
                                 ->method('incrementCommentCount');

        $this->incrementPostCountWhenForumPostPosted->handle($commentPosted);
    }
}