mirror of
https://github.com/Respect/Validation.git
synced 2026-03-15 06:45:44 +01:00
52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Validators;
|
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use PHPUnit\Framework\Attributes\Group;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use Respect\Validation\Exceptions\InvalidRuleConstructorException;
|
|
use Respect\Validation\Test\RuleTestCase;
|
|
|
|
#[Group('validator')]
|
|
#[CoversClass(SubdivisionCode::class)]
|
|
final class SubdivisionCodeTest extends RuleTestCase
|
|
{
|
|
#[Test]
|
|
public function shouldNotAcceptWrongNamesOnConstructor(): void
|
|
{
|
|
$this->expectException(InvalidRuleConstructorException::class);
|
|
$this->expectExceptionMessage('"whatever" is not a supported country code');
|
|
|
|
new SubdivisionCode('whatever');
|
|
}
|
|
|
|
/** @return iterable<array{SubdivisionCode, mixed}> */
|
|
public static function providerForValidInput(): iterable
|
|
{
|
|
return [
|
|
[new SubdivisionCode('AQ'), null],
|
|
[new SubdivisionCode('BR'), 'SP'],
|
|
[new SubdivisionCode('MV'), '00'],
|
|
[new SubdivisionCode('US'), 'CA'],
|
|
[new SubdivisionCode('YT'), ''],
|
|
];
|
|
}
|
|
|
|
/** @return iterable<array{SubdivisionCode, mixed}> */
|
|
public static function providerForInvalidInput(): iterable
|
|
{
|
|
return [
|
|
[new SubdivisionCode('BR'), 'CA'],
|
|
[new SubdivisionCode('MV'), 0],
|
|
[new SubdivisionCode('US'), 'CE'],
|
|
];
|
|
}
|
|
}
|