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
-------
a3cac2b4c9
[Intl] Extra timezone tests
This commit is contained in:
commit
1c110fa1f7
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Intl\Tests;
|
||||
|
||||
use Symfony\Component\Intl\Exception\MissingResourceException;
|
||||
use Symfony\Component\Intl\Regions;
|
||||
use Symfony\Component\Intl\Timezones;
|
||||
|
||||
/**
|
||||
@ -456,6 +458,15 @@ class TimezonesTest extends ResourceBundleTestCase
|
||||
'Pacific/Wake',
|
||||
'Pacific/Wallis',
|
||||
];
|
||||
private static $zonesNoCountry = [
|
||||
'Antarctica/Troll',
|
||||
'CST6CDT',
|
||||
'EST5EDT',
|
||||
'MST7MDT',
|
||||
'PST8PDT',
|
||||
'Etc/GMT',
|
||||
'Etc/UTC',
|
||||
];
|
||||
|
||||
public function testGetTimezones()
|
||||
{
|
||||
@ -562,4 +573,67 @@ class TimezonesTest extends ResourceBundleTestCase
|
||||
$this->assertSame(['Europe/Amsterdam'], Timezones::forCountryCode('NL'));
|
||||
$this->assertSame(['Europe/Berlin', 'Europe/Busingen'], Timezones::forCountryCode('DE'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
|
||||
*/
|
||||
public function testForCountryCodeWithUnknownCountry()
|
||||
{
|
||||
Timezones::forCountryCode('foobar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
|
||||
*/
|
||||
public function testGetCountryCodeWithUnknownTimezone()
|
||||
{
|
||||
Timezones::getCountryCode('foobar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideTimezones
|
||||
*/
|
||||
public function testGetGmtOffsetAvailability(string $timezone)
|
||||
{
|
||||
$this->assertInternalType('int', Timezones::getRawOffset($timezone));
|
||||
$this->assertInternalType('string', Timezones::getGmtOffset($timezone));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideTimezones
|
||||
*/
|
||||
public function testGetCountryCodeAvailability(string $timezone)
|
||||
{
|
||||
try {
|
||||
$this->assertInternalType('string', Timezones::getCountryCode($timezone));
|
||||
} catch (MissingResourceException $e) {
|
||||
if (\in_array($timezone, self::$zonesNoCountry, true)) {
|
||||
$this->markTestSkipped();
|
||||
} else {
|
||||
$this->fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function provideTimezones(): iterable
|
||||
{
|
||||
return array_map(function ($timezone) {
|
||||
return [$timezone];
|
||||
}, self::$zones);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideCountries
|
||||
*/
|
||||
public function testForCountryCodeAvailability(string $country)
|
||||
{
|
||||
$this->assertInternalType('array', Timezones::forCountryCode($country));
|
||||
}
|
||||
|
||||
public function provideCountries(): iterable
|
||||
{
|
||||
return array_map(function ($country) {
|
||||
return [$country];
|
||||
}, Regions::getRegionCodes());
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,15 @@ final class Timezones extends ResourceBundle
|
||||
|
||||
public static function forCountryCode(string $country): array
|
||||
{
|
||||
return self::readEntry(['CountryToZone', $country], 'meta');
|
||||
try {
|
||||
return self::readEntry(['CountryToZone', $country], 'meta');
|
||||
} catch (MissingResourceException $e) {
|
||||
if (Regions::exists($country)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
protected static function getPath(): string
|
||||
|
Reference in New Issue
Block a user