Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Translation] Added intl message formatter. #27399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 4, 2018
Prev Previous commit
Next Next commit
Be more specific with what exception we catch
  • Loading branch information
Nyholm committed Sep 4, 2018
commit fb30c7765907c042d32d51fc08a46883af9ba863
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Translation\Formatter;

use Symfony\Component\Translation\Exception\LogicException;
use Symfony\Component\Translation\Exception\InvalidArgumentException;

class FallbackFormatter implements MessageFormatterInterface, ChoiceMessageFormatterInterface
{
Expand All @@ -35,7 +36,7 @@ public function format($message, $locale, array $parameters = array())
{
try {
$result = $this->firstFormatter->format($message, $locale, $parameters);
} catch (\Throwable $e) {
} catch (InvalidArgumentException $e) {
return $this->secondFormatter->format($message, $locale, $parameters);
}

Expand All @@ -52,7 +53,7 @@ public function choiceFormat($message, $number, $locale, array $parameters = arr
if ($this->firstFormatter instanceof ChoiceMessageFormatterInterface && $this->secondFormatter instanceof ChoiceMessageFormatterInterface) {
try {
$result = $this->firstFormatter->choiceFormat($message, $number, $locale, $parameters);
} catch (\Throwable $e) {
} catch (InvalidArgumentException $e) {
return $this->secondFormatter->choiceFormat($message, $number, $locale, $parameters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Translation\Formatter\FallbackFormatter;
use Symfony\Component\Translation\Formatter\MessageFormatterInterface;


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be removed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be reverted

class FallbackFormatterTest extends \PHPUnit\Framework\TestCase
{
public function testFormatSame()
Expand Down Expand Up @@ -74,6 +75,23 @@ public function testFormatException()
$this->assertEquals('bar', (new FallbackFormatter($first, $second))->format('foo', 'en', array(2)));
}

public function testFormatExceptionUnknown()
{
$first = $this->getMockBuilder(MessageFormatterInterface::class)->setMethods(array('format'))->getMock();
$first
->expects($this->once())
->method('format')
->willThrowException(new \RuntimeException());

$second = $this->getMockBuilder(MessageFormatterInterface::class)->setMethods(array('format'))->getMock();
$second
->expects($this->exactly(0))
->method('format');

$this->expectException(\RuntimeException::class);
$this->assertEquals('bar', (new FallbackFormatter($first, $second))->format('foo', 'en', array(2)));
}

public function testChoiceFormatSame()
{
$first = $this->getMockBuilder(SuperFormatterInterface::class)->setMethods(array('format', 'choiceFormat'))->getMock();
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.