Skip to content

Commit

Permalink
Enable non_printable_character rule in php-cs-fixer config (yiisoft…
Browse files Browse the repository at this point in the history
…#14667)

* Use "\u{00a0}" as nbsp.

* Enable non_printable_character rule.

* Fix test for PHP 5.
  • Loading branch information
rob006 authored and cebe committed Aug 18, 2017
1 parent b99e955 commit 9b118aa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
2 changes: 1 addition & 1 deletion cs/src/YiiConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function __construct($name = 'yii-cs-config')
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
// 'non_printable_character' => true, // breaks Formatter::asCurrency() tests
'non_printable_character' => true,
'normalize_index_brace' => true,
'object_operator_without_whitespace' => true,
// 'ordered_class_elements' => [ // needs more discussion
Expand Down
2 changes: 1 addition & 1 deletion framework/messages/pt-BR/yii.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
'The verification code is incorrect.' => 'O código de verificação está incorreto.',
'Total <b>{count, number}</b> {count, plural, one{item} other{items}}.' => 'Total <b>{count, number}</b> {count, plural, one{item} other{itens}}.',
'Unable to verify your data submission.' => 'Não foi possível verificar o seu envio de dados.',
'Unknown alias: -{name}' => 'Alias ​​desconhecido: -{name}',
'Unknown alias: -{name}' => 'Alias desconhecido: -{name}',
'Unknown option: --{name}' => 'Opção desconhecida : --{name}',
'Update' => 'Alterar',
'View' => 'Exibir',
Expand Down
65 changes: 33 additions & 32 deletions tests/framework/i18n/FormatterNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,74 +247,75 @@ public function testIntlAsCurrency()
//$value = '-123456.123';
//$this->assertSame("($123,456.12)", $this->formatter->asCurrency($value));

// "\xc2\xa0" is used as non-breaking space explicitly
$this->formatter->locale = 'de-DE';
$this->formatter->currencyCode = null;
$this->assertSame('123,00 €', $this->formatter->asCurrency('123'));
$this->assertSame("123,00\xc2\xa0", $this->formatter->asCurrency('123'));
$this->formatter->currencyCode = 'USD';
$this->assertSame('123,00 $', $this->formatter->asCurrency('123'));
$this->assertSame("123,00\xc2\xa0$", $this->formatter->asCurrency('123'));
$this->formatter->currencyCode = 'EUR';
$this->assertSame('123,00 €', $this->formatter->asCurrency('123'));
$this->assertSame("123,00\xc2\xa0", $this->formatter->asCurrency('123'));

$this->formatter->locale = 'de-DE';
$this->formatter->currencyCode = null;
$this->assertSame('123,00 €', $this->formatter->asCurrency('123', 'EUR'));
$this->assertSame('123,00 $', $this->formatter->asCurrency('123', 'USD'));
$this->assertSame("123,00\xc2\xa0", $this->formatter->asCurrency('123', 'EUR'));
$this->assertSame("123,00\xc2\xa0$", $this->formatter->asCurrency('123', 'USD'));
$this->formatter->currencyCode = 'USD';
$this->assertSame('123,00 €', $this->formatter->asCurrency('123', 'EUR'));
$this->assertSame('123,00 $', $this->formatter->asCurrency('123', 'USD'));
$this->assertSame("123,00\xc2\xa0", $this->formatter->asCurrency('123', 'EUR'));
$this->assertSame("123,00\xc2\xa0$", $this->formatter->asCurrency('123', 'USD'));
$this->formatter->currencyCode = 'EUR';
$this->assertSame('123,00 €', $this->formatter->asCurrency('123', 'EUR'));
$this->assertSame('123,00 $', $this->formatter->asCurrency('123', 'USD'));
$this->assertSame("123,00\xc2\xa0", $this->formatter->asCurrency('123', 'EUR'));
$this->assertSame("123,00\xc2\xa0$", $this->formatter->asCurrency('123', 'USD'));

// default russian currency symbol
$this->formatter->locale = 'ru-RU';
$this->formatter->currencyCode = null;
$this->assertIsOneOf($this->formatter->asCurrency('123'), ['123,00 ₽', '123,00 руб.']);
$this->assertIsOneOf($this->formatter->asCurrency('123'), ["123,00\xc2\xa0", "123,00\xc2\xa0руб."]);
$this->formatter->currencyCode = 'RUB';
$this->assertIsOneOf($this->formatter->asCurrency('123'), ['123,00 ₽', '123,00 руб.']);
$this->assertIsOneOf($this->formatter->asCurrency('123'), ["123,00\xc2\xa0", "123,00\xc2\xa0руб."]);

// custom currency symbol
$this->formatter->currencyCode = null;
$this->formatter->numberFormatterSymbols = [
NumberFormatter::CURRENCY_SYMBOL => '',
];
$this->assertSame('123,00 ₽', $this->formatter->asCurrency('123'));
$this->assertSame("123,00\xc2\xa0", $this->formatter->asCurrency('123'));
$this->formatter->numberFormatterSymbols = [
NumberFormatter::CURRENCY_SYMBOL => 'RUR',
];
$this->assertSame('123,00 RUR', $this->formatter->asCurrency('123'));
$this->assertSame("123,00\xc2\xa0RUR", $this->formatter->asCurrency('123'));

/* See https://github.com/yiisoft/yii2/issues/13629
// setting the currency code overrides the symbol
$this->formatter->currencyCode = 'RUB';
$this->assertIsOneOf($this->formatter->asCurrency('123'), ['123,00 ₽', '123,00 руб.']);
$this->assertIsOneOf($this->formatter->asCurrency('123'), ["123,00\xc2\xa0₽", "123,00\xc2\xa0руб."]);
$this->formatter->numberFormatterSymbols = [NumberFormatter::CURRENCY_SYMBOL => '₽'];
$this->assertSame('123,00 $', $this->formatter->asCurrency('123', 'USD'));
$this->assertSame("123,00\xc2\xa0$", $this->formatter->asCurrency('123', 'USD'));
$this->formatter->numberFormatterSymbols = [NumberFormatter::CURRENCY_SYMBOL => '₽'];
$this->assertSame('123,00 €', $this->formatter->asCurrency('123', 'EUR'));
$this->assertSame("123,00\xc2\xa0€", $this->formatter->asCurrency('123', 'EUR'));
*/

// custom separators
$this->formatter->locale = 'de-DE';
$this->formatter->currencyCode = null;
$this->formatter->numberFormatterSymbols = [];
$this->formatter->thousandSeparator = ' ';
$this->assertSame('123 456,00 €', $this->formatter->asCurrency('123456', 'EUR'));
$this->assertSame("123 456,00\xc2\xa0", $this->formatter->asCurrency('123456', 'EUR'));

// empty input
$this->formatter->locale = 'de-DE';
$this->formatter->currencyCode = null;
$this->formatter->numberFormatterSymbols = [];
$this->formatter->thousandSeparator = null;
$this->assertSame('0,00 €', $this->formatter->asCurrency(false));
$this->assertSame('0,00 €', $this->formatter->asCurrency(''));
$this->assertSame("0,00\xc2\xa0", $this->formatter->asCurrency(false));
$this->assertSame("0,00\xc2\xa0", $this->formatter->asCurrency(''));

// decimal formatting
$this->formatter->locale = 'de-DE';
$this->assertSame('100 $', \Yii::$app->formatter->asCurrency(100, 'USD', [
$this->assertSame("100\xc2\xa0$", \Yii::$app->formatter->asCurrency(100, 'USD', [
NumberFormatter::MAX_FRACTION_DIGITS => 0,
]));
$this->assertSame('100,00 $', $this->formatter->asCurrency(100, 'USD', [
$this->assertSame("100,00\xc2\xa0$", $this->formatter->asCurrency(100, 'USD', [
NumberFormatter::MAX_FRACTION_DIGITS => 2,
]));

Expand All @@ -333,29 +334,29 @@ public function testIntlCurrencyFraction()
];
$this->formatter->locale = 'de-DE';
$this->formatter->currencyCode = null;
$this->assertSame('123 €', $this->formatter->asCurrency('123'));
$this->assertSame('123 €', $this->formatter->asCurrency('123', 'EUR'));
$this->assertSame("123\xc2\xa0", $this->formatter->asCurrency('123'));
$this->assertSame("123\xc2\xa0", $this->formatter->asCurrency('123', 'EUR'));
$this->formatter->currencyCode = 'USD';
$this->assertSame('123 $', $this->formatter->asCurrency('123'));
$this->assertSame('123 $', $this->formatter->asCurrency('123', 'USD'));
$this->assertSame('123 €', $this->formatter->asCurrency('123', 'EUR'));
$this->assertSame("123\xc2\xa0$", $this->formatter->asCurrency('123'));
$this->assertSame("123\xc2\xa0$", $this->formatter->asCurrency('123', 'USD'));
$this->assertSame("123\xc2\xa0", $this->formatter->asCurrency('123', 'EUR'));
$this->formatter->currencyCode = 'EUR';
$this->assertSame('123 €', $this->formatter->asCurrency('123'));
$this->assertSame('123 $', $this->formatter->asCurrency('123', 'USD'));
$this->assertSame('123 €', $this->formatter->asCurrency('123', 'EUR'));
$this->assertSame("123\xc2\xa0", $this->formatter->asCurrency('123'));
$this->assertSame("123\xc2\xa0$", $this->formatter->asCurrency('123', 'USD'));
$this->assertSame("123\xc2\xa0", $this->formatter->asCurrency('123', 'EUR'));

$this->formatter->locale = 'ru-RU';
$this->formatter->currencyCode = null;
$this->assertIsOneOf($this->formatter->asCurrency('123'), ['123 ₽', '123 руб.']);
$this->assertIsOneOf($this->formatter->asCurrency('123'), ["123\xc2\xa0", "123\xc2\xa0руб."]);

$this->formatter->numberFormatterSymbols = [
NumberFormatter::CURRENCY_SYMBOL => '&#8381;',
];
$this->assertSame('123 &#8381;', $this->formatter->asCurrency('123'));
$this->assertSame("123\xc2\xa0&#8381;", $this->formatter->asCurrency('123'));

$this->formatter->numberFormatterSymbols = [];
$this->formatter->currencyCode = 'RUB';
$this->assertIsOneOf($this->formatter->asCurrency('123'), ['123 ₽', '123 руб.']);
$this->assertIsOneOf($this->formatter->asCurrency('123'), ["123\xc2\xa0", "123\xc2\xa0руб."]);
}

/**
Expand Down

0 comments on commit 9b118aa

Please sign in to comment.