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

This commit is contained in:
Javier Eguiluz 2019-05-29 09:48:30 +02:00 committed by Nicolas Grekas
parent dd3dc1a684
commit f4ff47e47e
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;
}
}