From 343be111b50c7022a5137d9832fcae1698db94c5 Mon Sep 17 00:00:00 2001 From: Olivier Laviale Date: Mon, 19 Jan 2015 16:26:32 +0100 Subject: [PATCH] Fixing #1 --- lib/Locale.php | 5 +++++ tests/LocaleCollectionTest.php | 8 ++++++++ tests/LocaleTest.php | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/lib/Locale.php b/lib/Locale.php index 15b66bf..0bc64ca 100644 --- a/lib/Locale.php +++ b/lib/Locale.php @@ -85,6 +85,11 @@ class Locale implements \ArrayAccess */ public function __construct(Repository $repository, $code) { + if (!$code) + { + throw new \InvalidArgumentException("Locale identifier cannot be empty."); + } + $this->repository = $repository; $this->code = $code; } diff --git a/tests/LocaleCollectionTest.php b/tests/LocaleCollectionTest.php index 30bd9aa..f0935d8 100644 --- a/tests/LocaleCollectionTest.php +++ b/tests/LocaleCollectionTest.php @@ -49,4 +49,12 @@ public function test_existing_locale() $this->assertInstanceOf('ICanBoogie\CLDR\Locale', self::$collection['fr']); $this->assertInstanceOf('ICanBoogie\CLDR\Locale', self::$collection['en']); } + + /** + * @expectedException \InvalidArgumentException + */ + public function test_empty_identifier() + { + self::$collection['']; + } } diff --git a/tests/LocaleTest.php b/tests/LocaleTest.php index 79659a5..2b7aff9 100644 --- a/tests/LocaleTest.php +++ b/tests/LocaleTest.php @@ -130,6 +130,14 @@ public function provide_test_localize() ]; } + + /** + * @expectedException \InvalidArgumentException + */ + public function test_empty_identifier() + { + new Locale(get_repository(), ''); + } } namespace ICanBoogie\CLDR\LocaleTest;