64 lines
2.6 KiB
PHP
64 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Events;
|
|
|
|
use Domain\Enums\Units\OrderUnit;
|
|
use Domain\Events\AnOrderHasBeenPlaced;
|
|
use Domain\Events\Dto\OrderPlacedLine;
|
|
use Domain\Events\Dto\OrderPlacedShop;
|
|
use Domain\Models\ValueObjects\Entities\OrderId;
|
|
use Domain\Models\ValueObjects\IncoId;
|
|
use Domain\Models\ValueObjects\Matricule;
|
|
use Domain\Models\ValueObjects\OrderEmployee;
|
|
use Domain\Models\ValueObjects\OrderReference;
|
|
use Domain\Models\ValueObjects\ShopperEstablishmentCode;
|
|
use Domain\Models\ValueObjects\ShopperServiceCode;
|
|
use Domain\Models\ValueObjects\ShopperSiteCode;
|
|
use Money\Currency;
|
|
use Money\Money;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
describe('AnOrderHasBeenPlaced', function () {
|
|
it('creates an event when valid', function () {
|
|
// GIVEN
|
|
$uuid = Uuid::uuid7();
|
|
$orderId = new OrderId($uuid);
|
|
$reference = new OrderReference(Uuid::uuid7());
|
|
$totalTtc = new Money(1000, new Currency('EUR'));
|
|
$matricule = new Matricule('1234567');
|
|
$employee = new OrderEmployee($matricule, 'John', 'Doe', new ShopperEstablishmentCode('ETAB01'), new ShopperSiteCode('SITEA'), new ShopperServiceCode('101'));
|
|
$shop = new OrderPlacedShop('Shop', 'Address', '12345', 'City');
|
|
$pickupDay = new \DateTimeImmutable();
|
|
$lines = [
|
|
new OrderPlacedLine('Product', new IncoId(123), false, null, OrderUnit::PCE, 1, new Money(1000, new Currency('EUR'))),
|
|
];
|
|
|
|
// WHEN
|
|
$event = new AnOrderHasBeenPlaced($orderId, $reference, $totalTtc, $matricule, $employee, $shop, $pickupDay, $lines);
|
|
|
|
// THEN
|
|
expect($event->orderId)->toBe($orderId)
|
|
->and($event->reference)->toBe($reference);
|
|
});
|
|
|
|
it('throws exception if lines are empty', function () {
|
|
// GIVEN
|
|
$uuid = Uuid::uuid7();
|
|
$orderId = new OrderId($uuid);
|
|
$reference = new OrderReference(Uuid::uuid7());
|
|
$totalTtc = new Money(1000, new Currency('EUR'));
|
|
$matricule = new Matricule('1234567');
|
|
$employee = new OrderEmployee($matricule, 'John', 'Doe', new ShopperEstablishmentCode('ETAB01'), new ShopperSiteCode('SITEA'), new ShopperServiceCode('101'));
|
|
$shop = new OrderPlacedShop('Shop', 'Address', '12345', 'City');
|
|
$pickupDay = new \DateTimeImmutable();
|
|
$lines = [];
|
|
|
|
// WHEN
|
|
$action = fn () => new AnOrderHasBeenPlaced($orderId, $reference, $totalTtc, $matricule, $employee, $shop, $pickupDay, $lines);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'An order must have at least one line');
|
|
});
|
|
});
|