ldc-mesbr-app/tests/Unit/Domain/Models/ValueObjects/MoneyAmountTest.php

46 lines
1.3 KiB
PHP
Raw Normal View History

<?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 {
it('wraps a Money value', function (): void {
// GIVEN
$money = new Money(Currency::EUR, 300);
// WHEN
$amount = new MoneyAmount($money);
// THEN
expect($amount)->toBeInstanceOf(MoneyAmount::class)
->and($amount->value)->toBe($money);
});
it('implements equals by delegating to the wrapped Money', function (): void {
// GIVEN
$amount1 = new MoneyAmount(new Money(Currency::EUR, 300));
$amount2 = new MoneyAmount(new Money(Currency::EUR, 300));
$amount3 = new MoneyAmount(new Money(Currency::EUR, 500));
// 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
$amount = new MoneyAmount(new Money(Currency::EUR, 300));
// THEN
expect((string) $amount)->toBe((string) $amount->value);
});
});