<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CoreBundle\Tests\Entity;

use Ferienpass\CoreBundle\Entity\Edition;
use Ferienpass\CoreBundle\Entity\EditionLog;
use Ferienpass\CoreBundle\Entity\User;
use PHPUnit\Framework\TestCase;

final class EditionLogTest extends TestCase
{
    public function testGetIdIsNullByDefault(): void
    {
        $edition = new Edition();
        $log = new EditionLog($edition);

        self::assertNull($log->getId());
    }

    public function testToStringReturnsEmptyStringWhenNoId(): void
    {
        $edition = new Edition();
        $log = new EditionLog($edition);

        self::assertSame('', (string) $log);
    }

    public function testGetEditionReturnsEdition(): void
    {
        $edition = new Edition();
        $log = new EditionLog($edition);

        self::assertSame($edition, $log->getEdition());
    }

    public function testGetCreatedByIsNullByDefault(): void
    {
        $edition = new Edition();
        $log = new EditionLog($edition);

        self::assertNull($log->getCreatedBy());
    }

    public function testGetCreatedByReturnsUser(): void
    {
        $edition = new Edition();
        $user = new User();
        $log = new EditionLog($edition, $user);

        self::assertSame($user, $log->getCreatedBy());
    }

    public function testIsCommentReturnsFalseByDefault(): void
    {
        $edition = new Edition();
        $log = new EditionLog($edition);

        self::assertFalse($log->isComment());
    }

    public function testIsCommentReturnsTrueWhenCommentSet(): void
    {
        $edition = new Edition();
        $log = new EditionLog($edition, comment: 'Some note');

        self::assertTrue($log->isComment());
    }

    public function testGetCommentReturnsComment(): void
    {
        $edition = new Edition();
        $log = new EditionLog($edition, comment: 'My comment');

        self::assertSame('My comment', $log->getComment());
    }

    public function testGetCreatedAtIsSetOnConstruct(): void
    {
        $edition = new Edition();
        $log = new EditionLog($edition);

        self::assertInstanceOf(\DateTimeInterface::class, $log->getCreatedAt());
    }
}
