<?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\CreateTicketCommand;
use Chill\TicketBundle\Action\Ticket\Handler\CreateTicketCommandHandler;
use Chill\TicketBundle\Entity\EmergencyStatusEnum;
use Chill\TicketBundle\Entity\StateEnum;
use Chill\TicketBundle\Entity\Ticket;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Clock\MockClock;

/**
 * @internal
 *
 * @coversNothing
 */
class CreateTicketCommandHandlerTest extends TestCase
{
    private function getHandler(): CreateTicketCommandHandler
    {
        return new CreateTicketCommandHandler(new MockClock());
    }

    public function testHandleWithoutReference(): void
    {
        $command = new CreateTicketCommand();
        $actual = ($this->getHandler())($command);

        self::assertInstanceOf(Ticket::class, $actual);
        self::assertEquals('', $actual->getExternalRef());
        self::assertEquals(StateEnum::OPEN, $actual->getState());
        self::assertEquals(EmergencyStatusEnum::NO, $actual->getEmergencyStatus());
    }

    public function testHandleWithReference(): void
    {
        $command = new CreateTicketCommand($ref = 'external-ref');
        $actual = ($this->getHandler())($command);

        self::assertInstanceOf(Ticket::class, $actual);
        self::assertEquals($ref, $actual->getExternalRef());
        self::assertEquals(StateEnum::OPEN, $actual->getState());
        self::assertEquals(EmergencyStatusEnum::NO, $actual->getEmergencyStatus());
    }
}
