2026-08-14 11:33:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-08-14 15:38:10 +02:00
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects\Inco;
|
2026-08-14 11:33:05 +02:00
|
|
|
|
2026-08-14 15:38:10 +02:00
|
|
|
use Domain\Models\ValueObjects\Inco\PortionAmount;
|
2026-08-14 11:33:05 +02:00
|
|
|
|
|
|
|
|
covers(PortionAmount::class);
|
|
|
|
|
|
|
|
|
|
describe('PortionAmount Value Object Instantiation', function (): void {
|
|
|
|
|
it('can be instantiated with low and high parts', function (): void {
|
|
|
|
|
// GIVEN & WHEN
|
|
|
|
|
$portion = new PortionAmount(100.0, 150.0, true);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($portion->lowPart())->toBe(10000)
|
|
|
|
|
->and($portion->highPart())->toBe(15000)
|
|
|
|
|
->and($portion->approximative())->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('PortionAmount Value Object Domain Rules', function (): void {
|
|
|
|
|
it('throws DomainException for negative lowPart', function (): void {
|
|
|
|
|
// GIVEN, WHEN & THEN
|
|
|
|
|
expect(fn () => new PortionAmount(-1.0))
|
|
|
|
|
->toThrow(\DomainException::class, 'lowPart must be between 0 and');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('throws DomainException for negative highPart', function (): void {
|
|
|
|
|
// GIVEN, WHEN & THEN
|
|
|
|
|
expect(fn () => new PortionAmount(100.0, -1.0))
|
|
|
|
|
->toThrow(\DomainException::class, 'highPart must be between 0 and');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('throws DomainException for lowPart greater than highPart', function (): void {
|
|
|
|
|
// GIVEN, WHEN & THEN
|
|
|
|
|
expect(fn () => new PortionAmount(150.0, 100.0))
|
|
|
|
|
->toThrow(\DomainException::class, 'lowPart cannot be greater than highPart');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('throws DomainException for lowPart exceeding maximum value', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$maxMask = (1 << 15) - 1;
|
|
|
|
|
$scale = (int) pow(10, 2);
|
|
|
|
|
$maxValue = (float) bcdiv((string) $maxMask, (string) $scale, 2);
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect(fn () => new PortionAmount($maxValue + 0.01))
|
|
|
|
|
->toThrow(\DomainException::class, "lowPart must be between 0 and '{$maxValue}'");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('throws DomainException for highPart exceeding maximum value', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$maxMask = (1 << 15) - 1;
|
|
|
|
|
$scale = (int) pow(10, 2);
|
|
|
|
|
$maxValue = (float) bcdiv((string) $maxMask, (string) $scale, 2);
|
|
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect(fn () => new PortionAmount(100.0, $maxValue + 0.01))
|
|
|
|
|
->toThrow(\DomainException::class, "highPart must be between 0 and '{$maxValue}'");
|
|
|
|
|
});
|
|
|
|
|
});
|