forked from Skillshare/formatphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayNamesTest.php
More file actions
56 lines (49 loc) · 1.87 KB
/
DisplayNamesTest.php
File metadata and controls
56 lines (49 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
declare(strict_types=1);
namespace FormatPHP\Test\Intl;
use FormatPHP\Exception\UnableToFormatDisplayNameException;
use FormatPHP\Intl\DisplayNames;
use FormatPHP\Intl\DisplayNamesOptions;
use FormatPHP\Intl\Locale;
use FormatPHP\Test\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
class DisplayNamesTest extends TestCase
{
/**
* @param "region" | "script" $type
*/
#[DataProvider('invalidValueProvider')]
public function testThrowsExceptionForInvalidValue(string $value, string $type): void
{
$locale = new Locale('en-US');
$options = new DisplayNamesOptions(['type' => $type]);
$displayNames = new DisplayNames($locale, $options);
$this->expectException(UnableToFormatDisplayNameException::class);
$this->expectExceptionMessage("Invalid value \"$value\" for option $type");
$displayNames->of($value);
}
/**
* @return array<array{value: string, type: string}>
*/
public static function invalidValueProvider(): array
{
return [
['value' => 'A', 'type' => 'region'],
['value' => 'a', 'type' => 'region'],
['value' => 'AAA', 'type' => 'region'],
['value' => 'aaa', 'type' => 'region'],
['value' => '1', 'type' => 'region'],
['value' => '12', 'type' => 'region'],
['value' => '1234', 'type' => 'region'],
['value' => 'A', 'type' => 'script'],
['value' => 'Ab', 'type' => 'script'],
['value' => 'Abc', 'type' => 'script'],
['value' => 'Abcde', 'type' => 'script'],
['value' => 'Abc1', 'type' => 'script'],
['value' => 'a', 'type' => 'currency'],
['value' => 'ab', 'type' => 'currency'],
['value' => 'abcd', 'type' => 'currency'],
['value' => 'ab1', 'type' => 'currency'],
];
}
}