forked from Skillshare/formatphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayNamesOptionsTest.php
More file actions
115 lines (105 loc) · 3.31 KB
/
DisplayNamesOptionsTest.php
File metadata and controls
115 lines (105 loc) · 3.31 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
declare(strict_types=1);
namespace FormatPHP\Test\Intl;
use FormatPHP\Intl\DisplayNamesOptions;
use FormatPHP\Test\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use function constant;
use function json_encode;
/**
* @phpstan-import-type OptionsType from DisplayNamesOptions
*/
class DisplayNamesOptionsTest extends TestCase
{
#[DataProvider('publicConstantsProvider')]
public function testPublicConstants(string $constantName, int | string $expectedValue): void
{
$this->assertSame(constant($constantName), $expectedValue);
}
/**
* @return array<array{constantName: string, expectedValue: string | int}>
*/
public static function publicConstantsProvider(): array
{
$class = DisplayNamesOptions::class;
return [
[
'constantName' => "$class::FALLBACK_CODE",
'expectedValue' => 'code',
],
[
'constantName' => "$class::FALLBACK_NONE",
'expectedValue' => 'none',
],
[
'constantName' => "$class::LANGUAGE_DISPLAY_DIALECT",
'expectedValue' => 'dialect',
],
[
'constantName' => "$class::LANGUAGE_DISPLAY_STANDARD",
'expectedValue' => 'standard',
],
[
'constantName' => "$class::STYLE_LONG",
'expectedValue' => 'long',
],
[
'constantName' => "$class::STYLE_NARROW",
'expectedValue' => 'narrow',
],
[
'constantName' => "$class::STYLE_SHORT",
'expectedValue' => 'short',
],
[
'constantName' => "$class::TYPE_CALENDAR",
'expectedValue' => 'calendar',
],
[
'constantName' => "$class::TYPE_CURRENCY",
'expectedValue' => 'currency',
],
[
'constantName' => "$class::TYPE_DATE_TIME_FIELD",
'expectedValue' => 'dateTimeField',
],
[
'constantName' => "$class::TYPE_LANGUAGE",
'expectedValue' => 'language',
],
[
'constantName' => "$class::TYPE_REGION",
'expectedValue' => 'region',
],
[
'constantName' => "$class::TYPE_SCRIPT",
'expectedValue' => 'script',
],
];
}
/**
* @param OptionsType $options
*/
#[DataProvider('constructorOptionsProvider')]
public function testConstructorOptions(array $options): void
{
$formatOptions = new DisplayNamesOptions($options);
$this->assertJsonStringEqualsJsonString(
(string) json_encode((object) $options),
(string) json_encode($formatOptions),
);
}
/**
* @return array<array{options: OptionsType}>
*/
public static function constructorOptionsProvider(): array
{
return [
['options' => []],
['options' => ['fallback' => 'code']],
['options' => ['languageDisplay' => 'standard']],
['options' => ['style' => 'long']],
['options' => ['type' => 'region']],
];
}
}