toBe(['subtotal_minor' => 2, 'tax_minor' => 2, 'total_minor' => 4]) ->and($second)->toBe(['subtotal_minor' => 1, 'tax_minor' => 1, 'total_minor' => 2]) ->and($first['total_minor'] + $second['total_minor'])->toBe(6); }); test('consolidation preserves separate origin rates instead of averaging them', function () { $a = OrderPartsReference::portion(0, 0, 100, 16, '63.25'); $b = OrderPartsReference::portion(0, 0, 200, 32, '64.75'); expect($a)->toBe(['subtotal_minor' => 6325, 'tax_minor' => 1012, 'total_minor' => 7337]) ->and($b)->toBe(['subtotal_minor' => 12950, 'tax_minor' => 2072, 'total_minor' => 15022]) ->and($a['total_minor'] + $b['total_minor'])->toBe(22359); }); test('partial invoices within a partial order preserve the source offset', function () { $order = OrderPartsReference::portion(1, 1, 3, 2, '1.5'); $first = OrderPartsReference::portion(1, 1, 1, 1, '1.5'); $second = OrderPartsReference::portion(2, 2, 2, 1, '1.5'); foreach (['subtotal_minor', 'tax_minor', 'total_minor'] as $field) { expect($first[$field] + $second[$field])->toBe($order[$field]); } }); test('invalid reference bases are refused before arithmetic', function (int $before, int $net, string $rate) { expect(fn () => OrderPartsReference::portion($before, 0, $net, 0, $rate))->toThrow(InvalidArgumentException::class); })->with([[-1, 1, '1'], [0, -1, '1'], [PHP_INT_MAX, 1, '1'], [0, 1, '0'], [0, 1, '-1'], [0, 100000000000000, '2']]);