SetLastCommentWhenCommentPostedTest.php 1.34 KB
<?php

namespace FootyRoom\Tests\Integration\ForumPost;

use FootyRoom\Core\Comment\Author;
use FootyRoom\Core\Comment\Comment;
use FootyRoom\Core\ForumPost\ForumPostCommentPosted;
use FootyRoom\Core\ForumPost\SetLastCommentWhenCommentPosted;
use FootyRoom\Core\ForumPost\ForumPost;
use FootyRoom\Queries\PostQuery;
use FootyRoom\Tests\TestCase;

class SetLastCommentWhenCommentPostedTest extends TestCase
{
    public function setup()
    {
        $this->mockPostQuery = $this->getMockBuilder(PostQuery::class)
                            ->disableOriginalConstructor()
                            ->getMock();

        $this->setLastCommentWhenCommentPosted = new SetLastCommentWhenCommentPosted($this->mockPostQuery);
    }

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

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

        $post = new ForumPost('title', 1, 1);

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

        $this->mockPostQuery->expects($this->once())
                            ->method('updateLastComment');

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