2015-10-17 17:50:52 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2015-10-17 17:50:52 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-10-17 17:50:52 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2020-08-26 09:47:59 +02:00
|
|
|
use Respect\Validation\Exceptions\ComponentException;
|
2018-06-13 05:01:03 +02:00
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
2017-11-04 11:21:40 +01:00
|
|
|
|
2015-10-17 17:50:52 +02:00
|
|
|
/**
|
2018-06-13 05:01:03 +02:00
|
|
|
* @group rule
|
|
|
|
*
|
2017-02-04 14:01:14 +01:00
|
|
|
* @covers \Respect\Validation\Rules\CountryCode
|
2018-06-13 05:01:03 +02:00
|
|
|
*
|
|
|
|
* @author Felipe Martins <me@fefas.net>
|
|
|
|
* @author Gabriel Caruso <carusogabriel34@gmail.com>
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
2018-11-25 17:20:02 +01:00
|
|
|
* @author William Espindola <oi@williamespindola.com.br>
|
2015-10-17 17:50:52 +02:00
|
|
|
*/
|
2018-06-13 05:01:03 +02:00
|
|
|
final class CountryCodeTest extends RuleTestCase
|
2015-10-17 17:50:52 +02:00
|
|
|
{
|
2015-10-17 21:16:07 +02:00
|
|
|
/**
|
2018-06-13 05:01:03 +02:00
|
|
|
* @test
|
2015-10-17 21:16:07 +02:00
|
|
|
*/
|
2018-06-13 05:01:03 +02:00
|
|
|
public function itShouldThrowsExceptionWhenInvalidFormat(): void
|
2015-10-17 21:16:07 +02:00
|
|
|
{
|
2020-08-26 09:47:59 +02:00
|
|
|
$this->expectException(ComponentException::class);
|
|
|
|
$this->expectExceptionMessage(
|
|
|
|
'"whatever" is not a valid set for ISO 3166-1 (Available: alpha-2, alpha-3, numeric)'
|
|
|
|
);
|
|
|
|
|
2015-10-17 21:16:07 +02:00
|
|
|
new CountryCode('whatever');
|
|
|
|
}
|
|
|
|
|
2015-10-17 17:50:52 +02:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2015-10-17 17:50:52 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForValidInput(): array
|
2015-10-17 17:50:52 +02:00
|
|
|
{
|
2018-06-13 05:01:03 +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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2015-10-17 17:50:52 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForInvalidInput(): array
|
2015-10-17 17:50:52 +02:00
|
|
|
{
|
2018-06-13 05:01:03 +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
|
|
|
}
|
|
|
|
}
|