1
0
Fork 0
mirror of https://github.com/archtechx/money.git synced 2025-12-12 11:24:03 +00:00
money/tests/Pest/CurrencyTest.php
David Andersson 269274586a
Fixes #11 - Remove trailing zeros from formatted price (#18)
* Remove trailing zeros from formatted price

* Add setting for how to handle trailing decimal zeros

* Write tests

* Fix code style

* Rewrite function description

* Change test name

* Add empty line at end of file

* rename deleteTrailingDecimalZeros to trimTrailingDecimalZeros

* Fix grammar

* Remove unnecessary parameter declarations

* fix test name

* fix comment grammar

* fix docblock grammar

Co-authored-by: Samuel Štancl <samuel@archte.ch>
2022-05-16 13:12:13 +02:00

43 lines
1.2 KiB
PHP

<?php
use ArchTech\Money\Currency;
use ArchTech\Money\Exceptions\InvalidCurrencyException;
use ArchTech\Money\Tests\Currencies\CZK;
test("a currency is invalid if it doesn't have a name", function () {
pest()->expectException(InvalidCurrencyException::class);
new Currency(rate: 2.0, code: 'CZK');
});
test("a currency is invalid if it doesn't have a code", function () {
pest()->expectException(InvalidCurrencyException::class);
new Currency(rate: 2.0, name: 'Czech Crown');
});
test('currencies can be serialized to JSON', function () {
expect(json_encode(new CZK))->json()->toBe([
'code' => 'CZK',
'name' => 'Czech Crown',
'rate' => 25,
'prefix' => '',
'suffix' => ' Kč',
'mathDecimals' => 2,
'displayDecimals' => 0,
'rounding' => 2,
'decimalSeparator' => ',',
'thousandsSeparator' => '.',
'trimTrailingDecimalZeros' => false,
]);
});
test('currencies can be created from JSON', function () {
$original = new Currency(code: 'GBP', rate: 0.8, name: 'British Pound');
$json = json_encode($original);
$new = Currency::fromJson($json);
expect($original->toArray())->toBe($new->toArray());
});