47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects\Coupon;
|
|
|
|
use Domain\Models\ValueObjects\Coupon\CouponMovement;
|
|
|
|
covers(CouponMovement::class);
|
|
|
|
describe('coupon movement', function (): void {
|
|
it('keeps the given quantity and creation date', function (): void {
|
|
// GIVEN
|
|
$quantity = 10;
|
|
$createdAt = new \DateTimeImmutable('2026-01-01 12:00:00');
|
|
|
|
// WHEN
|
|
$movement = new CouponMovement($quantity, $createdAt);
|
|
|
|
// THEN
|
|
expect($movement->quantity)->toBe($quantity)
|
|
->and($movement->createdAt)->toBe($createdAt);
|
|
});
|
|
|
|
it('defaults the creation date to now', function (): void {
|
|
// GIVEN
|
|
$before = new \DateTimeImmutable();
|
|
|
|
// WHEN
|
|
$movement = new CouponMovement(5);
|
|
|
|
// THEN
|
|
$after = new \DateTimeImmutable();
|
|
|
|
expect($movement->createdAt)->toBeInstanceOf(\DateTimeImmutable::class)
|
|
->and($movement->createdAt >= $before)->toBeTrue()
|
|
->and($movement->createdAt <= $after)->toBeTrue();
|
|
});
|
|
|
|
it('accepts a negative quantity', function (): void {
|
|
// GIVEN / WHEN
|
|
$movement = new CouponMovement(-3);
|
|
|
|
// THEN
|
|
expect($movement->quantity)->toBe(-3);
|
|
});
|
|
});
|