cents)->toBe($cents); })->with([ 'whole euros' => ['85', 8500], 'comma decimals' => ['85,50', 8550], 'one decimal' => ['85.5', 8550], 'thousands with a space' => ['1 200,00', 120000], 'with the euro sign' => ['0,59 €', 59], 'zero' => ['0', 0], ]); it('treats an empty value as no amount', function () { expect(Money::parse(' '))->toBeNull(); }); it('rejects amounts that are not euros with at most two decimals', function (string $typed) { Money::parse($typed); })->throws(InvalidMoneyAmount::class)->with(['-5', '1,234', 'abc', '1.000,00', '1000001']); it('formats with a no-break space and the currency', function () { $money = Money::fromCents(120050); expect($money->format())->toBe("1\u{00A0}200,50\u{00A0}€") ->and($money->inputValue())->toBe('1200,50'); }); it('adds and removes VAT, rounding half up to the cent', function (int $net, string $vat, int $gross) { $percentage = VatPercentage::parse($vat); expect(Money::fromCents($net)->addVat($percentage)->cents)->toBe($gross); })->with([ 'general rate' => [1434, '25,5', 1800], 'rounds half up' => [2, '25', 3], 'reduced rate' => [1000, '13,5', 1135], 'zero rate' => [999, '0', 999], ]); it('works out the price without VAT from a consumer price', function () { expect(Money::fromCents(1800)->removeVat(VatPercentage::parse('25,5'))->cents)->toBe(1434) ->and(Money::fromCents(1000)->removeVat(VatPercentage::parse('0'))->cents)->toBe(1000); }); it('parses and formats VAT percentages', function () { expect(VatPercentage::parse('25,5 %')->basisPoints)->toBe(2550) ->and(VatPercentage::parse('13.5')->format())->toBe("13,5\u{00A0}%") ->and(VatPercentage::parse('0')->inputValue())->toBe('0'); }); it('rejects invalid VAT percentages', function (string $typed) { VatPercentage::parse($typed); })->throws(InvalidVatPercentage::class)->with(['', '-1', '100,01', '12,345', 'abc']);