Skip to content

Commit

Permalink
test: formatAsDecimal
Browse files Browse the repository at this point in the history
  • Loading branch information
npbreland committed Feb 14, 2024
1 parent 562f159 commit 45b80ba
Showing 1 changed file with 82 additions and 24 deletions.
106 changes: 82 additions & 24 deletions tests/MoneyFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace Pelmered\FilamentMoneyField\Tests;
use Money\Currency;
use Pelmered\FilamentMoneyField\MoneyFormatter;
use PHPUnit\Framework;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;

#[CoversClass(MoneyFormatter::class)]
final class MoneyFormatterTest extends TestCase
{
public static function provideMoneyDataSEK(): array
Expand Down Expand Up @@ -33,6 +35,32 @@ public static function provideMoneyDataSEK(): array
];
}

public static function provideDecimalMoneyDataSEK(): array
{
return [
'thousands' => [
1000000,
'10 000,00',
],
'decimals' => [
10045,
'100,45',
],
'millions' => [
123456789,
'1 234 567,89',
],
'empty_string' => [
'',
'',
],
'null' => [
null,
'',
],
];
}

public static function provideMoneyDataUSD(): array
{
return [
Expand All @@ -59,6 +87,32 @@ public static function provideMoneyDataUSD(): array
];
}

public static function provideDecimalMoneyDataUSD(): array
{
return [
'thousands' => [
1000000,
'10,000.00',
],
'decimals' => [
10045,
'100.45',
],
'millions' => [
123456789,
'1,234,567.89',
],
'empty_string' => [
'',
'',
],
'null' => [
null,
'',
],
];
}

public static function provideDecimalDataSEK(): array
{
return [
Expand Down Expand Up @@ -110,13 +164,17 @@ public static function provideDecimalDataUSD(): array
],
];
}

#[DataProvider('provideMoneyDataUSD')]
public function testMoneyFormatterUSD(mixed $input, string $expectedOutput)
{
self::assertSame(
static::replaceNonBreakingSpaces($expectedOutput),
MoneyFormatter::format($input, new Currency('USD'), 'en_US')
);
}


/**
* @covers MoneyFormatter::format
* @dataProvider provideMoneyDataSEK
*/
#[Framework\CoversClass(MoneyFormatter::class)]
#[DataProvider('provideMoneyDataSEK')]
public function testMoneyFormatterSEK(mixed $input, string $expectedOutput)
{
self::assertSame(
Expand All @@ -125,24 +183,28 @@ public function testMoneyFormatterSEK(mixed $input, string $expectedOutput)
);
}

/**
* @covers MoneyFormatter::format
* @dataProvider provideMoneyDataUSD
*/
#[Framework\CoversClass(MoneyFormatter::class)]
public function testMoneyFormatterUSD(mixed $input, string $expectedOutput)
#[DataProvider('provideDecimalMoneyDataUSD')]
//#[CoversClass(MoneyFormatter::class)]
public function testMoneyDecimalFormatterUSD(mixed $input, string $expectedOutput)
{
self::assertSame(
static::replaceNonBreakingSpaces($expectedOutput),
MoneyFormatter::format($input, new Currency('USD'), 'en_US')
MoneyFormatter::formatAsDecimal($input, new Currency('USD'), 'en_US')
);
}

/**
* @covers MoneyFormatter::parseDecimal
* @dataProvider provideDecimalDataSEK
*/
#[Framework\CoversClass(MoneyFormatter::class)]
#[DataProvider('provideDecimalMoneyDataSEK')]
//#[CoversClass(MoneyFormatter::class)]
public function testMoneyDecimalFormatterSEK(mixed $input, string $expectedOutput)
{
self::assertSame(
static::replaceNonBreakingSpaces($expectedOutput),
MoneyFormatter::formatAsDecimal($input, new Currency('SEK'), 'sv_SE')
);
}

#[DataProvider('provideDecimalDataSEK')]
//#[CoversClass(MoneyFormatter::class)]
public function testMoneyParserDecimalSEK(mixed $input, string $expectedOutput)
{
self::assertSame(
Expand All @@ -151,11 +213,7 @@ public function testMoneyParserDecimalSEK(mixed $input, string $expectedOutput)
);
}

/**
* @covers MoneyFormatter::parseDecimal
* @dataProvider provideDecimalDataUSD
*/
#[Framework\CoversClass(MoneyFormatter::class)]
#[DataProvider('provideDecimalDataUSD')]
public function testMoneyParserDecimalUSD(mixed $input, string $expectedOutput)
{
self::assertSame(
Expand Down

0 comments on commit 45b80ba

Please sign in to comment.