ldc-boutique-cnc-sable/tests/Unit/Domain/Events/DtoTest.php
2026-10-27 09:58:12 +01:00

153 lines
4.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Events;
use Domain\Enums\Units\OrderUnit;
use Domain\Events\Dto\OrderPlacedLine;
use Domain\Events\Dto\OrderPlacedShop;
use Domain\Events\Dto\RegateOrderCsvGenerated;
use Domain\Events\Dto\SalariesHaveBeenImported;
use Domain\Models\ValueObjects\IncoId;
use Domain\Models\ValueObjects\Matricule;
use Money\Currency;
use Money\Money;
describe('OrderPlacedLine', function () {
it('creates OrderPlacedLine correctly', function () {
// GIVEN
$productName = 'Product';
$incoId = new IncoId(1);
$unit = OrderUnit::PCE;
$price = new Money(2000, new Currency('EUR'));
// WHEN
$line = new OrderPlacedLine($productName, $incoId, false, null, $unit, 2, $price);
// THEN
expect($line->quantity)->toBe(2);
});
it('throws exception if quantity is zero or less for OrderPlacedLine', function () {
// GIVEN
$productName = 'Product';
$incoId = new IncoId(1);
$unit = OrderUnit::PCE;
$price = new Money(2000, new Currency('EUR'));
// WHEN
$action = fn () => new OrderPlacedLine($productName, $incoId, false, null, $unit, 0, $price);
// THEN
expect($action)->toThrow(\DomainException::class, 'Quantity must be greater than 0');
});
});
describe('OrderPlacedShop', function () {
it('creates OrderPlacedShop correctly', function () {
// GIVEN
$name = 'Name';
$address = 'Addr';
$zip = '12345';
$city = 'City';
// WHEN
$shop = new OrderPlacedShop($name, $address, $zip, $city);
// THEN
expect($shop->name)->toBe('Name');
});
it('throws exception if shop name is empty', function () {
// GIVEN
$name = ' ';
$address = 'Addr';
$zip = '12345';
$city = 'City';
// WHEN
$action = fn () => new OrderPlacedShop($name, $address, $zip, $city);
// THEN
expect($action)->toThrow(\DomainException::class, 'Shop name is required');
});
it('throws exception if shop address is empty', function () {
// GIVEN
$name = 'Name';
$address = '';
$zip = '12345';
$city = 'City';
// WHEN
$action = fn () => new OrderPlacedShop($name, $address, $zip, $city);
// THEN
expect($action)->toThrow(\DomainException::class, 'Shop address is required');
});
it('throws exception if shop postcode is empty', function () {
// GIVEN
$name = 'Name';
$address = 'Addr';
$zip = '';
$city = 'City';
// WHEN
$action = fn () => new OrderPlacedShop($name, $address, $zip, $city);
// THEN
expect($action)->toThrow(\DomainException::class, 'Shop postcode is required');
});
it('throws exception if shop city is empty', function () {
// GIVEN
$name = 'Name';
$address = 'Addr';
$zip = '12345';
$city = ' ';
// WHEN
$action = fn () => new OrderPlacedShop($name, $address, $zip, $city);
// THEN
expect($action)->toThrow(\DomainException::class, 'Shop city is required');
});
});
describe('RegateOrderCsvGenerated', function () {
it('creates RegateOrderCsvGenerated correctly', function () {
// GIVEN
$csvContent = 'csv';
$fileName = 'file.csv';
// WHEN
$dto = new RegateOrderCsvGenerated($csvContent, $fileName);
// THEN
expect($dto->csvContent)->toBe('csv')
->and($dto->fileName)->toBe('file.csv');
});
});
describe('SalariesHaveBeenImported', function () {
it('creates SalariesHaveBeenImported correctly', function () {
// GIVEN
$adminId = 'admin1';
$matricules = [new Matricule('1234567')];
// WHEN
$dto = new SalariesHaveBeenImported($adminId, $matricules);
// THEN
expect($dto->adminId)->toBe('admin1');
});
it('throws exception if SalariesHaveBeenImported gets non-matricule', function () {
// GIVEN
$adminId = 'admin1';
$matricules = ['1234567'];
// WHEN
$action = fn () => new SalariesHaveBeenImported($adminId, $matricules);
// THEN
expect($action)->toThrow(\UnexpectedValueException::class);
});
});