commit melhorias compras5
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-22 19:39:09 +02:00
parent 36dcfdf00c
commit db1615fac1
79 changed files with 4082 additions and 120 deletions
+22
View File
@@ -0,0 +1,22 @@
<?php
use App\Services\PurchaseLineAmounts;
test('successive native portions preserve the original line price and VAT exactly', function () {
$first = PurchaseLineAmounts::portion(223, '16.00', 0, 400);
$second = PurchaseLineAmounts::portion(223, '16.00', 400, 600);
$third = PurchaseLineAmounts::portion(223, '16.00', 1000, 700);
expect($first)->toBe(['subtotal_minor' => 89, 'tax_minor' => 14, 'total_minor' => 103])
->and($second)->toBe(['subtotal_minor' => 134, 'tax_minor' => 22, 'total_minor' => 156])
->and($third)->toBe(['subtotal_minor' => 156, 'tax_minor' => 25, 'total_minor' => 181])
->and($first['total_minor'] + $second['total_minor'] + $third['total_minor'])->toBe(440);
});
test('a half-cent remainder is not rounded again when the original quantity offset is retained', function () {
expect(PurchaseLineAmounts::portion(1, '0', 0, 500))->toBe(['subtotal_minor' => 1, 'tax_minor' => 0, 'total_minor' => 1])
->and(PurchaseLineAmounts::portion(1, '0', 500, 500))->toBe(['subtotal_minor' => 0, 'tax_minor' => 0, 'total_minor' => 0]);
});
test('invalid cumulative bases are refused without truncation or floating arithmetic', function (int $price, string $tax, int $before, int $quantity) {
expect(fn () => PurchaseLineAmounts::portion($price, $tax, $before, $quantity))->toThrow(InvalidArgumentException::class);
})->with([[-1, '0', 0, 1], [1, '-1', 0, 1], [1, '0', -1, 1], [1, '0', 0, 0], [1, '0', PHP_INT_MAX, 1]]);