respect-validation/tests/unit/Rules/CountryCodeTest.php

70 lines
1.9 KiB
PHP
Raw Normal View History

2015-10-17 17:50:52 +02:00
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
2015-10-17 17:50:52 +02:00
*/
declare(strict_types=1);
2015-10-17 17:50:52 +02:00
namespace Respect\Validation\Rules;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Test\RuleTestCase;
2017-11-04 11:21:40 +01:00
2015-10-17 17:50:52 +02:00
/**
* @group rule
*
2017-02-04 14:01:14 +01:00
* @covers \Respect\Validation\Rules\CountryCode
*
* @author Felipe Martins <me@fefas.net>
* @author Gabriel Caruso <carusogabriel34@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
2015-10-17 17:50:52 +02:00
*/
final class CountryCodeTest extends RuleTestCase
2015-10-17 17:50:52 +02:00
{
/**
* @test
*/
public function itShouldThrowsExceptionWhenInvalidFormat(): void
{
$this->expectException(ComponentException::class);
$this->expectExceptionMessage(
'"whatever" is not a valid set for ISO 3166-1 (Available: alpha-2, alpha-3, numeric)'
);
new CountryCode('whatever');
}
2015-10-17 17:50:52 +02:00
/**
* {@inheritDoc}
2015-10-17 17:50:52 +02:00
*/
public static function providerForValidInput(): array
2015-10-17 17:50:52 +02:00
{
return [
[new CountryCode(CountryCode::ALPHA2), 'BR'],
[new CountryCode(CountryCode::ALPHA3), 'BRA'],
[new CountryCode(CountryCode::NUMERIC), '076'],
[new CountryCode(CountryCode::ALPHA2), 'DE'],
[new CountryCode(CountryCode::ALPHA3), 'DEU'],
[new CountryCode(CountryCode::NUMERIC), '276'],
[new CountryCode(CountryCode::ALPHA2), 'US'],
[new CountryCode(CountryCode::ALPHA3), 'USA'],
[new CountryCode(CountryCode::NUMERIC), '840'],
];
2015-10-17 17:50:52 +02:00
}
/**
* {@inheritDoc}
2015-10-17 17:50:52 +02:00
*/
public static function providerForInvalidInput(): array
2015-10-17 17:50:52 +02:00
{
return [
[new CountryCode(CountryCode::ALPHA2), 'USA'],
[new CountryCode(CountryCode::ALPHA3), 'US'],
[new CountryCode(CountryCode::NUMERIC), '000'],
];
2015-10-17 17:50:52 +02:00
}
}