ldc-mesbr-app/tests/Unit/Domain/Models/ValueObjects/Stock/StockAdjustmentTest.php
2026-09-23 16:18:08 +02:00

56 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\ValueObjects\Stock;
use Domain\Models\ValueObjects\Actor\ActorId;
use Domain\Models\ValueObjects\Stock\StockAdjustment;
covers(StockAdjustment::class);
describe('stock adjustment', function (): void {
it('creates a valid stock adjustment', function (): void {
// GIVEN
$quantity = 10;
$reason = 'Inventory correction';
$actorId = ActorId::generate();
// WHEN
$adjustment = new StockAdjustment($quantity, $reason, $actorId);
// THEN
expect($adjustment)->toBeInstanceOf(StockAdjustment::class)
->and($adjustment->quantity)->toBe($quantity)
->and($adjustment->reason)->toBe($reason)
->and($adjustment->actorId)->toBe($actorId)
->and($adjustment->createdAt)->toBeNull();
});
it('creates a stock adjustment with an explicit createdAt date', function (): void {
// GIVEN
$createdAt = new \DateTimeImmutable('2026-06-15 12:00:00', new \DateTimeZone('UTC'));
// WHEN
$adjustment = new StockAdjustment(10, 'Inventory correction', ActorId::generate(), $createdAt);
// THEN
expect($adjustment->createdAt)->toBe($createdAt);
});
it('rejects a quantity of zero', function (): void {
// WHEN
$action = fn (): StockAdjustment => new StockAdjustment(0, 'Inventory correction', ActorId::generate());
// THEN
expect($action)->toThrow(\DomainException::class, 'Stock Amount should be more than 0.');
});
it('rejects a negative quantity', function (): void {
// WHEN
$action = fn (): StockAdjustment => new StockAdjustment(-5, 'Inventory correction', ActorId::generate());
// THEN
expect($action)->toThrow(\DomainException::class, 'Stock Amount should be more than 0.');
});
});