1
0
Fork 0
mirror of https://github.com/archtechx/money.git synced 2025-12-12 03:14:03 +00:00

Initial commit

This commit is contained in:
Samuel Štancl 2021-11-16 19:06:57 +01:00
commit 8847454577
33 changed files with 2435 additions and 0 deletions

View file

@ -0,0 +1,42 @@
<?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' => '.',
]);
});
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());
});