mirror of
https://github.com/archtechx/money.git
synced 2025-12-12 11:24:03 +00:00
Write tests
This commit is contained in:
parent
8fc9d4d455
commit
c3e85c3e5d
5 changed files with 32 additions and 1 deletions
|
|
@ -15,4 +15,5 @@ class CZK extends Currency
|
||||||
protected string $thousandsSeparator = '.';
|
protected string $thousandsSeparator = '.';
|
||||||
protected int $rounding = 2;
|
protected int $rounding = 2;
|
||||||
protected string $suffix = ' Kč';
|
protected string $suffix = ' Kč';
|
||||||
|
protected bool $deleteTrailingDecimalZeros = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,4 +13,5 @@ class EUR extends Currency
|
||||||
protected int $displayDecimals = 2;
|
protected int $displayDecimals = 2;
|
||||||
protected int $rounding = 0;
|
protected int $rounding = 0;
|
||||||
protected string $suffix = ' €';
|
protected string $suffix = ' €';
|
||||||
|
protected bool $deleteTrailingDecimalZeros = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
tests/Currencies/SEK.php
Normal file
17
tests/Currencies/SEK.php
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ArchTech\Money\Tests\Currencies;
|
||||||
|
|
||||||
|
use ArchTech\Money\Currency;
|
||||||
|
|
||||||
|
class SEK extends Currency
|
||||||
|
{
|
||||||
|
protected string $code = 'SEK';
|
||||||
|
protected string $name = 'Swedish crown';
|
||||||
|
protected float $rate = 9.94;
|
||||||
|
protected int $mathDecimals = 4;
|
||||||
|
protected int $displayDecimals = 2;
|
||||||
|
protected int $rounding = 0;
|
||||||
|
protected string $suffix = ' kr';
|
||||||
|
protected bool $deleteTrailingDecimalZeros = true;
|
||||||
|
}
|
||||||
|
|
@ -28,6 +28,7 @@ test('currencies can be serialized to JSON', function () {
|
||||||
'rounding' => 2,
|
'rounding' => 2,
|
||||||
'decimalSeparator' => ',',
|
'decimalSeparator' => ',',
|
||||||
'thousandsSeparator' => '.',
|
'thousandsSeparator' => '.',
|
||||||
|
'deleteTrailingDecimalZeros' => false,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,9 @@ use ArchTech\Money\Currency;
|
||||||
use ArchTech\Money\Money;
|
use ArchTech\Money\Money;
|
||||||
use ArchTech\Money\Tests\Currencies\CZK;
|
use ArchTech\Money\Tests\Currencies\CZK;
|
||||||
use ArchTech\Money\Tests\Currencies\EUR;
|
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 () {
|
test('prefixes are applied', function () {
|
||||||
expect(Money::fromDecimal(10.00, USD::class)->formatted())->toBe('$10.00');
|
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' => ',', 'prefix' => '$$$']))->toBe('$$$10,45');
|
||||||
expect(Money::fromDecimal(10.45)->formatted(decimalSeparator: ',', suffix: ' USD'))->toBe('$10,45 USD');
|
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 €');
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue