AdjustPostCountWhenForumPostMovedTest.php 2.11 KB
<?php

namespace FootyRoom\Tests\Integration\ForumCategory;

use FootyRoom\Core\ForumCategory\AdjustPostCountWhenForumPostMoved;
use FootyRoom\Core\ForumPost\Moved;
use FootyRoom\Core\ForumPost\ForumPost;
use FootyRoom\Repositories\ForumCategoryRepository;
use FootyRoom\Tests\TestCase;

class AdjustPostCountWhenForumPostMovedTest extends TestCase
{
    public function setup()
    {
        $this->mockForumCategoryRepository = $this->getMockBuilder(ForumCategoryRepository::class)
                            ->disableOriginalConstructor()
                            ->getMock();

        $this->adjustPostCountWhenForumPostMoved = new AdjustPostCountWhenForumPostMoved($this->mockForumCategoryRepository);
    }

    public function testCountWillNotBeChangedIfCatagoryIdIsSame()
    {
        $previousCategoryId = 60;

        $title = 'title';
        $newCategoryId = 60;
        $userId = 41301;

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

        $moved = new Moved($forumPost, $previousCategoryId);

        $this->mockForumCategoryRepository->expects($this->never())
                                          ->method('decrementPostCount');

        $this->mockForumCategoryRepository->expects($this->never())
                                          ->method('incrementPostCount');

        $this->adjustPostCountWhenForumPostMoved->handle($moved);
    }

    public function testCountWillBeChangedIfCatagoryIdNotSame()
    {
        $previousCategoryId = 60;

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

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

        $moved = new Moved($forumPost, $previousCategoryId);

        $this->mockForumCategoryRepository->expects($this->once())
                                          ->method('decrementPostCount');

        $this->mockForumCategoryRepository->expects($this->once())
                                          ->method('incrementPostCount');

        $this->adjustPostCountWhenForumPostMoved->handle($moved);
    }
}