Skip to content

Commit 98e7de6

Browse files
javiereguiluznicolas-grekas
authored andcommitted
[Intl] Improve the error message when country code is wrong
1 parent 878c556 commit 98e7de6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Tests/TimezonesTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,15 @@ public function testForCountryCodeWithUnknownCountry()
603603
Timezones::forCountryCode('foobar');
604604
}
605605

606+
/**
607+
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
608+
* @expectedExceptionMessage Country codes must be in uppercase, but "nl" was passed. Try with "NL" country code instead.
609+
*/
610+
public function testForCountryCodeWithWrongCountryCode()
611+
{
612+
Timezones::forCountryCode('nl');
613+
}
614+
606615
/**
607616
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
608617
*/

Timezones.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ public static function forCountryCode(string $country): array
109109
return [];
110110
}
111111

112+
if (Countries::exists(strtoupper($country))) {
113+
throw new MissingResourceException(sprintf('Country codes must be in uppercase, but "%s" was passed. Try with "%s" country code instead.', $country, strtoupper($country)));
114+
}
115+
112116
throw $e;
113117
}
114118
}

0 commit comments

Comments
 (0)