Skip to content

Commit

Permalink
Add tests for parsing issue in isssue #20
Browse files Browse the repository at this point in the history
  • Loading branch information
pelmered committed Apr 22, 2024
1 parent 71c5ebc commit 4240ed5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/MoneyFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function parseDecimal($moneyString, Currency $currency, string $lo
$numberFormatter = self::getNumberFormatter($locale, NumberFormatter::DECIMAL);
$moneyParser = new IntlLocalizedDecimalParser($numberFormatter, $currencies);

// Needed to fix some parsing issues with small numbers such as "2,00" with "," as thousands separator
// Needed to fix some parsing issues with small numbers such as "2,00" with "," left as thousands separator in the wrong place
// See: https://github.com/pelmered/filament-money-field/issues/20
$formattingRules = self::getFormattingRules($locale);
$moneyString = str_replace($formattingRules->groupingSeparator, '', $moneyString);
Expand Down
14 changes: 12 additions & 2 deletions tests/MoneyFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public static function provideDecimalDataUSD(): array
],
];
}

#[DataProvider('provideMoneyDataUSD')]
public function testMoneyFormatterUSD(mixed $input, string $expectedOutput)
{
Expand Down Expand Up @@ -202,7 +202,7 @@ public function testMoneyDecimalFormatterSEK(mixed $input, string $expectedOutpu
MoneyFormatter::formatAsDecimal($input, new Currency('SEK'), 'sv_SE')
);
}

#[DataProvider('provideDecimalDataSEK')]
//#[CoversClass(MoneyFormatter::class)]
public function testMoneyParserDecimalSEK(mixed $input, string $expectedOutput)
Expand All @@ -221,4 +221,14 @@ public function testMoneyParserDecimalUSD(mixed $input, string $expectedOutput)
MoneyFormatter::parseDecimal($input, new Currency('USD'), 'en_US')
);
}

public static function testMoneyParserDecimal(): void
{
// Tests for some parsing issues with small numbers such as "2,00" with "," left as thousands separator in the wrong place
// See: https://github.com/pelmered/filament-money-field/issues/20
self::assertSame(
'20000',
MoneyFormatter::parseDecimal('2,00', new Currency('USD'), 'en_US')
);
}
}

0 comments on commit 4240ed5

Please sign in to comment.