money = new Money(Currency::EUR, 300); $this->secondMoney = new Money(Currency::EUR, 200); $this->minimumMoney = new Money(Currency::EUR, 1); $this->zeroMoney = new Money(Currency::EUR, 0); $this->aboveLimitMoney = new Money(Currency::EUR, 301); }); 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); }); it('accepts the minimum amount of 0.01€', function (): void { // GIVEN / WHEN $amount = new MoneyAmount($this->minimumMoney); // THEN expect($amount->value)->toBe($this->minimumMoney); }); it('accepts the maximum amount of 3.00€', function (): void { // GIVEN / WHEN $amount = new MoneyAmount($this->money); // THEN expect($amount->value)->toBe($this->money); }); it('throws when the amount is zero', function (): void { // GIVEN / WHEN / THEN expect(fn () => new MoneyAmount($this->zeroMoney)) ->toThrow(\DomainException::class, 'Money amount must be between 0.01€ and 3.00€'); }); it('throws when the amount is above 3.00€', function (): void { // GIVEN / WHEN / THEN expect(fn () => new MoneyAmount($this->aboveLimitMoney)) ->toThrow(\DomainException::class, 'Money amount must be between 0.01€ and 3.00€'); }); });