Skip to content

Commit

Permalink
Add test to validate, passing empty string throws CannotInstantiateFo…
Browse files Browse the repository at this point in the history
…rmatter.
  • Loading branch information
harikt committed Oct 24, 2016
1 parent 3fc8904 commit 4e81ed9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/IntlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
9 changes: 9 additions & 0 deletions tests/IntlFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down

0 comments on commit 4e81ed9

Please sign in to comment.