Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit d339881

Browse files
committed
feat(tests): added Timezone tests
1 parent c15838c commit d339881

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

tests/TimezoneTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace ProgrammatorDev\YetAnotherPhpValidator\Test;
4+
5+
use ProgrammatorDev\YetAnotherPhpValidator\Exception\TimezoneException;
6+
use ProgrammatorDev\YetAnotherPhpValidator\Rule\Timezone;
7+
use ProgrammatorDev\YetAnotherPhpValidator\Test\Util\TestRuleFailureConditionTrait;
8+
use ProgrammatorDev\YetAnotherPhpValidator\Test\Util\TestRuleMessageOptionTrait;
9+
use ProgrammatorDev\YetAnotherPhpValidator\Test\Util\TestRuleSuccessConditionTrait;
10+
use ProgrammatorDev\YetAnotherPhpValidator\Test\Util\TestRuleUnexpectedValueTrait;
11+
12+
class TimezoneTest extends AbstractTest
13+
{
14+
use TestRuleUnexpectedValueTrait;
15+
use TestRuleFailureConditionTrait;
16+
use TestRuleSuccessConditionTrait;
17+
use TestRuleMessageOptionTrait;
18+
19+
public static function provideRuleUnexpectedValueData(): \Generator
20+
{
21+
$missingCountryCodeMessage = '/A country code is required when timezone group is \\\DateTimeZone::PER_COUNTRY./';
22+
$invalidCountryCodeMessage = '/The "(.*)" value is not a valid "(.*)" country code, "(.*)" given./';
23+
24+
yield 'missing country code' => [new Timezone(\DateTimeZone::PER_COUNTRY), 'Europe/Lisbon', $missingCountryCodeMessage];
25+
yield 'invalid country code' => [new Timezone(\DateTimeZone::PER_COUNTRY, 'PRT'), 'Europe/Lisbon', $invalidCountryCodeMessage];
26+
}
27+
28+
public static function provideRuleFailureConditionData(): \Generator
29+
{
30+
$exception = TimezoneException::class;
31+
$message = '/The "(.*)" value is not a valid timezone, "(.*)" given./';
32+
33+
yield 'invalid timezone' => [new Timezone(), 'Invalid/Timezone', $exception, $message];
34+
yield 'not of timezone group' => [new Timezone(\DateTimeZone::AFRICA), 'Europe/Lisbon', $exception, $message];
35+
yield 'not of timezone country' => [new Timezone(\DateTimeZone::PER_COUNTRY, 'es'), 'Europe/Lisbon', $exception, $message];
36+
}
37+
38+
public static function provideRuleSuccessConditionData(): \Generator
39+
{
40+
yield 'valid timezone' => [new Timezone(), 'Europe/Lisbon'];
41+
yield 'is of timezone group' => [new Timezone(\DateTimeZone::EUROPE), 'Europe/Lisbon'];
42+
yield 'is of multiple timezone groups' => [new Timezone(\DateTimeZone::EUROPE | \DateTimeZone::UTC), 'UTC'];
43+
yield 'is of timezone country' => [new Timezone(\DateTimeZone::PER_COUNTRY, 'pt'), 'Europe/Lisbon'];
44+
}
45+
46+
public static function provideRuleMessageOptionData(): \Generator
47+
{
48+
yield 'message' => [
49+
new Timezone(
50+
message: 'The "{{ name }}" value "{{ value }}" is not a valid timezone.'
51+
),
52+
'Invalid/Timezone',
53+
'The "test" value "Invalid/Timezone" is not a valid timezone.'
54+
];
55+
}
56+
57+
}

0 commit comments

Comments
 (0)