<?php

declare(strict_types=1);

/*
 * Chill is a software for social workers
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Chill\TicketBundle\Tests\Action\Ticket\Handler;

use Chill\TicketBundle\Action\Ticket\AddCommentCommand;
use Chill\TicketBundle\Action\Ticket\Handler\AddCommentCommandHandler;
use Chill\TicketBundle\Entity\Comment;
use Chill\TicketBundle\Entity\Ticket;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;

/**
 * @internal
 *
 * @coversNothing
 */
class AddCommentCommandHandlerTest extends TestCase
{
    use ProphecyTrait;

    public function testAddComment(): void
    {
        $handler = $this->buildCommand();

        $ticket = new Ticket();
        $command = new AddCommentCommand(content: 'test');

        $handler->handle($ticket, $command);

        self::assertCount(1, $ticket->getComments());
        self::assertEquals('test', $ticket->getComments()[0]->getContent());
    }

    private function buildCommand(): AddCommentCommandHandler
    {
        $entityManager = $this->prophesize(EntityManagerInterface::class);
        $entityManager->persist(Argument::type(Comment::class))->shouldBeCalled();

        return new AddCommentCommandHandler($entityManager->reveal());
    }
}
