diff --git a/src/IntlFormatter.php b/src/IntlFormatter.php index 07c37b6..8f3dfca 100644 --- a/src/IntlFormatter.php +++ b/src/IntlFormatter.php @@ -64,6 +64,9 @@ public function format($locale, $string, array $tokens_values) try { $formatter = new MessageFormatter($locale, $string); + if (! $formatter) { + $this->throwCannotInstantiateFormatter(); + } } catch (\Exception $e) { $this->throwCannotInstantiateFormatter(); } diff --git a/tests/IntlFormatterTest.php b/tests/IntlFormatterTest.php index a0da3e2..32db820 100644 --- a/tests/IntlFormatterTest.php +++ b/tests/IntlFormatterTest.php @@ -168,6 +168,15 @@ public function testIssue6($tokens_values, $expect) $this->assertSame($expect, $actual); } + public function testEmptyStringThrowsException() + { + $locale = 'en_US'; + $string = ''; + $formatter = $this->newFormatter(); + $this->setExpectedException('Aura\Intl\Exception\CannotInstantiateFormatter'); + $actual = $formatter->format($locale, $string, []); + } + public function provide_testIssue6() { return [