ldc-mesbr-app/tests/Unit/Domain/Models/ValueObjects/MoneyAmountTest.php
2026-10-02 12:48:00 +02:00

57 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\ValueObjects;
use Domain\Models\ValueObjects\MoneyAmount;
use Shared\Enums\Currency;
use Shared\ValueObjects\Money;
covers(MoneyAmount::class);
describe('money amount', function (): void {
beforeEach(function (): void {
$this->money = new Money(Currency::EUR, 300);
$this->secondMoney = new Money(Currency::EUR, 500);
});
it('wraps a Money value', function (): void {
// GIVEN / WHEN
$amount = new MoneyAmount(
$this->money
);
// THEN
expect($amount)->toBeInstanceOf(MoneyAmount::class)
->and($amount->value)->toBe($this->money);
});
it('implements equals by delegating to the wrapped Money', function (): void {
// GIVEN / WHEN
$amount1 = new MoneyAmount(
$this->money
);
$amount2 = new MoneyAmount(
$this->money
);
$amount3 = new MoneyAmount(
$this->secondMoney
);
// THEN
expect($amount1->equals($amount2))->toBeTrue()
->and($amount1->equals($amount3))->toBeFalse()
->and($amount1->equals(null))->toBeFalse();
});
it('converts to string by delegating to the wrapped Money', function (): void {
// GIVEN / WHEN
$amount = new MoneyAmount(
$this->money
);
// THEN
expect((string) $amount)->toBe((string) $amount->value);
});
});