diff --git a/tests/Currencies/CZK.php b/tests/Currencies/CZK.php index 6cb93c5..75ccac4 100644 --- a/tests/Currencies/CZK.php +++ b/tests/Currencies/CZK.php @@ -15,4 +15,5 @@ class CZK extends Currency protected string $thousandsSeparator = '.'; protected int $rounding = 2; protected string $suffix = ' Kč'; + protected bool $deleteTrailingDecimalZeros = false; } diff --git a/tests/Currencies/EUR.php b/tests/Currencies/EUR.php index 5890eac..d4c9719 100644 --- a/tests/Currencies/EUR.php +++ b/tests/Currencies/EUR.php @@ -13,4 +13,5 @@ class EUR extends Currency protected int $displayDecimals = 2; protected int $rounding = 0; protected string $suffix = ' €'; + protected bool $deleteTrailingDecimalZeros = false; } diff --git a/tests/Currencies/SEK.php b/tests/Currencies/SEK.php new file mode 100644 index 0000000..c647ec0 --- /dev/null +++ b/tests/Currencies/SEK.php @@ -0,0 +1,17 @@ + 2, 'decimalSeparator' => ',', 'thousandsSeparator' => '.', + 'deleteTrailingDecimalZeros' => false, ]); }); diff --git a/tests/Pest/FormattingTest.php b/tests/Pest/FormattingTest.php index fda4e03..da75f38 100644 --- a/tests/Pest/FormattingTest.php +++ b/tests/Pest/FormattingTest.php @@ -5,8 +5,9 @@ use ArchTech\Money\Currency; use ArchTech\Money\Money; use ArchTech\Money\Tests\Currencies\CZK; use ArchTech\Money\Tests\Currencies\EUR; +use ArchTech\Money\Tests\Currencies\SEK; -beforeEach(fn () => currencies()->add([CZK::class, EUR::class])); +beforeEach(fn () => currencies()->add([CZK::class, EUR::class, SEK::class])); test('prefixes are applied', function () { expect(Money::fromDecimal(10.00, USD::class)->formatted())->toBe('$10.00'); @@ -45,3 +46,13 @@ test('the format method accepts overrides', function () { expect(Money::fromDecimal(10.45)->formatted(['decimalSeparator' => ',', 'prefix' => '$$$']))->toBe('$$$10,45'); expect(Money::fromDecimal(10.45)->formatted(decimalSeparator: ',', suffix: ' USD'))->toBe('$10,45 USD'); }); + +test('setting for deleting trailing decimal zeros', function () { + expect(Money::fromDecimal(10.00, SEK::class)->formatted())->toBe('10 kr'); + expect(Money::fromDecimal(10.10, SEK::class)->formatted())->toBe('10.1 kr'); + expect(Money::fromDecimal(10.12, SEK::class)->formatted())->toBe('10.12 kr'); + + expect(Money::fromDecimal(10.00, EUR::class)->formatted())->toBe('10.00 €'); + expect(Money::fromDecimal(10.10, EUR::class)->formatted())->toBe('10.10 €'); + expect(Money::fromDecimal(10.12, EUR::class)->formatted())->toBe('10.12 €'); +}); \ No newline at end of file