mirror of
https://github.com/archtechx/money.git
synced 2025-12-12 03:14:03 +00:00
43 lines
1.2 KiB
PHP
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' => '.',
|
|
'deleteTrailingDecimalZeros' => 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());
|
|
});
|