1+ <?php
2+
3+ namespace ProgrammatorDev \Validator \Test ;
4+
5+ use ProgrammatorDev \Validator \Exception \LocaleException ;
6+ use ProgrammatorDev \Validator \Rule \Locale ;
7+ use ProgrammatorDev \Validator \Test \Util \TestRuleFailureConditionTrait ;
8+ use ProgrammatorDev \Validator \Test \Util \TestRuleMessageOptionTrait ;
9+ use ProgrammatorDev \Validator \Test \Util \TestRuleSuccessConditionTrait ;
10+ use ProgrammatorDev \Validator \Test \Util \TestRuleUnexpectedValueTrait ;
11+
12+ class LocaleTest extends AbstractTest
13+ {
14+ use TestRuleUnexpectedValueTrait;
15+ use TestRuleFailureConditionTrait;
16+ use TestRuleSuccessConditionTrait;
17+ use TestRuleMessageOptionTrait;
18+
19+ public static function provideRuleUnexpectedValueData (): \Generator
20+ {
21+ $ unexpectedTypeMessage = '/Expected value of type "string", (.*) given\./ ' ;
22+
23+ yield 'invalid type ' => [new Locale (), 123 , $ unexpectedTypeMessage ];
24+ }
25+
26+ public static function provideRuleFailureConditionData (): \Generator
27+ {
28+ $ exception = LocaleException::class;
29+ $ message = '/The (.*) value is not a valid locale, (.*) given\./ ' ;
30+
31+ yield 'invalid ' => [new Locale (), 'invalid ' , $ exception , $ message ];
32+ yield 'uncanonicalized 1 ' => [new Locale (), 'pt_pt ' , $ exception , $ message ];
33+ yield 'uncanonicalized 2 ' => [new Locale (), 'pt-PT ' , $ exception , $ message ];
34+ yield 'uncanonicalized 3 ' => [new Locale (), 'PT-pt.utf8 ' , $ exception , $ message ];
35+ }
36+
37+ public static function provideRuleSuccessConditionData (): \Generator
38+ {
39+ yield 'language code ' => [new Locale (), 'pt ' ];
40+ yield 'language and country code ' => [new Locale (), 'pt_PT ' ];
41+ yield 'canonicalized 1 ' => [new Locale (canonicalize: true ), 'pt_pt ' ];
42+ yield 'canonicalized 2 ' => [new Locale (canonicalize: true ), 'pt-PT ' ];
43+ yield 'canonicalized 3 ' => [new Locale (canonicalize: true ), 'PT-pt.utf8 ' ];
44+ }
45+
46+ public static function provideRuleMessageOptionData (): \Generator
47+ {
48+ yield 'message ' => [
49+ new Locale (
50+ message: '{{ name }} {{ value }} '
51+ ),
52+ 'invalid ' ,
53+ 'test "invalid" '
54+ ];
55+ }
56+ }
0 commit comments