<?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\CmsBundle\Tests\Form\SimpleType;

use Ferienpass\CmsBundle\Form\SimpleType\AccessCodeType;
use Ferienpass\CoreBundle\Entity\AccessCode;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\Extension\Core\Type\TextType;

final class AccessCodeTypeTest extends TestCase
{
    public function testGetParentReturnsTextType(): void
    {
        self::assertSame(TextType::class, new AccessCodeType()->getParent());
    }

    public function testTransformReturnsNullForNull(): void
    {
        self::assertNull(new AccessCodeType()->transform(null));
    }

    public function testTransformReturnsNullForNonAccessCode(): void
    {
        self::assertNull(new AccessCodeType()->transform('some_string'));
    }

    public function testTransformReturnsCodeStringForAccessCode(): void
    {
        /** @var AccessCode&MockObject $code */
        $code = $this->createMock(AccessCode::class);
        $code->method('getCode')->willReturn('ABC-123');

        self::assertSame('ABC-123', new AccessCodeType()->transform($code));
    }

    public function testReverseTransformReturnsNullForEmptyValue(): void
    {
        self::assertNull(new AccessCodeType()->reverseTransform(''));
        self::assertNull(new AccessCodeType()->reverseTransform(null));
    }
}
