10000 bug #31325 [Intl] Extra timezone tests (ro0NL) · symfony/symfony@1c110fa · GitHub
[go: up one dir, main page]

Skip to content

Commit 1c110fa

Browse files
committed
bug #31325 [Intl] Extra timezone tests (ro0NL)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Intl] Extra timezone tests | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes (including intl-data group) | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Guarantees timezone data integrity. Ideally to go before #31292 :) Commits ------- a3cac2b [Intl] Extra timezone tests
2 parents 2dacfca + a3cac2b commit 1c110fa

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

src/Symfony/Component/Intl/Tests/TimezonesTest.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Intl\Tests;
1313

14+
use Symfony\Component\Intl\Exception\MissingResourceException;
15+
use Symfony\Component\Intl\Regions;
1416
use Symfony\Component\Intl\Timezones;
1517

1618
/**
@@ -456,6 +458,15 @@ class TimezonesTest extends ResourceBundleTestCase
456458
'Pacific/Wake',
457459
'Pacific/Wallis',
458460
];
461+
private static $zonesNoCountry = [
462+
'Antarctica/Troll',
463+
'CST6CDT',
464+
'EST5EDT',
465+
'MST7MDT',
466+
'PST8PDT',
467+
'Etc/GMT',
468+
'Etc/UTC',
469+
];
459470

460471
public function testGetTimezones()
461472
{
@@ -562,4 +573,67 @@ public function testForCountryCode()
562573
$this->assertSame(['Europe/Amsterdam'], Timezones::forCountryCode('NL'));
563574
$this->assertSame(['Europe/Berlin', 'Europe/Busingen'], Timezones::forCountryCode('DE'));
564575
}
576+
577+
/**
578+
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
579+
*/
580+
public function testForCountryCodeWithUnknownCountry()
581+
{
582+
Timezones::forCountryCode('foobar');
583+
}
584+
585+
/**
586+
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
587+
*/
588+
public function testGetCountryCodeWithUnknownTimezone()
589+
{
590+
Timezones::getCountryCode('foobar');
591+
}
592+
593+
/**
594+
* @dataProvider provideTimezones
595+
*/
596+
public function testGetGmtOffsetAvailability(string $timezone)
597+
{
598+
$this->assertInternalType('int', Timezones::getRawOffset($timezone));
599+
$this->assertInternalType('string', Timezones::getGmtOffset($timezone));
600+
}
601+
602+
/**
603+
* @dataProvider provideTimezones
604+
*/
605+
public function testGetCountryCodeAvailability(string $timezone)
606+
{
607+
try {
608+
$this->assertInternalType('string', Timezones::getCountryCode($timezone));
609+
} catch (MissingResourceException $e) {
610+
if (\in_array($timezone, self::$zonesNoCountry, true)) {
611+
$this->markTestSkipped();
612+
} else {
613+
$this->fail();
614+
}
615+
}
616+
}
617+
618+
public function provideTimezones(): iterable
619+
{
620+
return array_map(function ($timezone) {
621+
return [$timezone];
622+
}, self::$zones);
623+
}
624+
625+
/**
626+
* @dataProvider provideCountries
627+
*/
628+
public function testForCountryCodeAvailability(string $country)
629+
{
630+
$this->assertInternalType('array', Timezones::forCountryCode($country));
631+
}
632+
633+
public function provideCountries(): iterable
634+
{
635+
return array_map(function ($country) {
636+
return [$country];
637+
}, Regions::getRegionCodes());
638+
}
565639
}

src/Symfony/Component/Intl/Timezones.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,15 @@ public static function getCountryCode(string $timezone): string
8383

8484
public static function forCountryCode(string $country): array
8585
{
86-
return self::readEntry(['CountryToZone', $country], 'meta');
86+
try {
87+
return self::readEntry(['CountryToZone', $country], 'meta');
88+
} catch (MissingResourceException $e) {
89+
if (Regions::exists($country)) {
90+
return [];
91+
}
92+
93+
throw $e;
94+
}
8795
}
8896

8997
protected static function getPath(): string

0 commit comments

Comments
 (0)
0