-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Intl] Extra timezone tests #31325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Intl] Extra timezone tests #31325
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 @@ public function testForCountryCode() | |
$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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if it is possible for valid timezone ids to throw a MissingResourceException when trying to get their code, we need to document that in the interface, as it becomes necessary to catch it when using it (or maybe the Timezones class should handle that internally) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see #31332 |
||
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()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we ensure that with return types instead ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it does :D im on it.