minor #31677 [Intl] Improve the error message when country code is wrong (javiereguiluz)

This PR was merged into the 4.3 branch.

Discussion
----------

[Intl] Improve the error message when country code is wrong

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #31656
| License       | MIT
| Doc PR        | (not needed)

Commits
-------

f4ff47e47e [Intl] Improve the error message when country code is wrong
This commit is contained in:
Nicolas Grekas 2019-05-29 20:04:27 +02:00
commit e9f3a9d0f0
2 changed files with 13 additions and 0 deletions

View File

@ -603,6 +603,15 @@ class TimezonesTest extends ResourceBundleTestCase
Timezones::forCountryCode('foobar');
}
/**
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
* @expectedExceptionMessage Country codes must be in uppercase, but "nl" was passed. Try with "NL" country code instead.
*/
public function testForCountryCodeWithWrongCountryCode()
{
Timezones::forCountryCode('nl');
}
/**
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
*/

View File

@ -109,6 +109,10 @@ final class Timezones extends ResourceBundle
return [];
}
if (Countries::exists(strtoupper($country))) {
throw new MissingResourceException(sprintf('Country codes must be in uppercase, but "%s" was passed. Try with "%s" country code instead.', $country, strtoupper($country)));
}
throw $e;
}
}