|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Intl\Tests;
|
13 | 13 |
|
| 14 | +use Symfony\Component\Intl\Exception\MissingResourceException; |
| 15 | +use Symfony\Component\Intl\Regions; |
14 | 16 | use Symfony\Component\Intl\Timezones;
|
15 | 17 |
|
16 | 18 | /**
|
@@ -456,6 +458,15 @@ class TimezonesTest extends ResourceBundleTestCase
|
456 | 458 | 'Pacific/Wake',
|
457 | 459 | 'Pacific/Wallis',
|
458 | 460 | ];
|
| 461 | + private static $zonesNoCountry = [ |
| 462 | + 'Antarctica/Troll', |
| 463 | + 'CST6CDT', |
| 464 | + 'EST5EDT', |
| 465 | + 'MST7MDT', |
| 466 | + 'PST8PDT', |
| 467 | + 'Etc/GMT', |
| 468 | + 'Etc/UTC', |
| 469 | + ]; |
459 | 470 |
|
460 | 471 | public function testGetTimezones()
|
461 | 472 | {
|
@@ -562,4 +573,67 @@ public function testForCountryCode()
|
562 | 573 | $this->assertSame(['Europe/Amsterdam'], Timezones::forCountryCode('NL'));
|
563 | 574 | $this->assertSame(['Europe/Berlin', 'Europe/Busingen'], Timezones::forCountryCode('DE'));
|
564 | 575 | }
|
| 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 | + } |
565 | 639 | }
|
0 commit comments