<?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\Validator;

use Ferienpass\CoreBundle\Validator\AccessCodeValidator;
use Ferienpass\CoreBundle\Validator\ValidAccessCode;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;

final class AccessCodeValidatorTest extends TestCase
{
    public function testNullValueDoesNotAddViolation(): void
    {
        $context = $this->createMock(ExecutionContextInterface::class);
        $context->expects(self::never())->method('buildViolation');

        $validator = new AccessCodeValidator();
        $validator->initialize($context);
        $validator->validate(null, new ValidAccessCode());
    }

    public function testWrongConstraintThrowsUnexpectedTypeException(): void
    {
        $this->expectException(UnexpectedTypeException::class);

        $context = $this->createMock(ExecutionContextInterface::class);
        $validator = new AccessCodeValidator();
        $validator->initialize($context);
        $validator->validate(null, $this->createMock(Constraint::class));
    }
}
