SubscribeToPostWhenCommentPostedInForumTest.php 2.09 KB
<?php

namespace FootyRoom\Tests\Integration\Subscription;

use FootyRoom\Core\Comment\Author;
use FootyRoom\Core\Comment\Comment;
use FootyRoom\Core\ForumPost\ForumPost;
use FootyRoom\Core\ForumPost\ForumPostCommentPosted;
use FootyRoom\Core\Subscription\SubscribeToPostWhenCommentPostedInForum;
use FootyRoom\Queries\Subscription\SubscriptionQueryHandler;
use FootyRoom\Repositories\SubscriptionRepository;
use FootyRoom\Tests\TestCase;

class SubscribeToPostWhenCommentPostedInForumTest extends TestCase
{
    public function setup()
    {
        $this->mockSubscriptionRepository = $this->getMockBuilder(SubscriptionRepository::class)
                            ->disableOriginalConstructor()
                            ->getMock();

        $this->mockSubscriptionQueryHandler = $this->getMockBuilder(SubscriptionQueryHandler::class)
                            ->disableOriginalConstructor()
                            ->getMock();

        $this->subscribeToPostWhenCommentPostedInForum = new SubscribeToPostWhenCommentPostedInForum(
            $this->mockSubscriptionRepository,
            $this->mockSubscriptionQueryHandler
        );
    }

    public function testCreateSubscriptionWillNotBeCalledIfAlreadyHaveSubscription()
    {
        $discussionId = 'forumPost:1';
        $author = new Author(41301, 'chanBC');
        $content = 'test content';
        $html = '';

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

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

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

        $commentPosted = new ForumPostCommentPosted($comment, $post);

        $this->mockSubscriptionQueryHandler->method('findOne')
                                           ->will($this->returnValue(true));

        $this->mockSubscriptionRepository->expects($this->never())
                                           ->method('create');

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