2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects;
|
|
|
|
|
|
|
|
|
|
use Domain\Models\ValueObjects\Matricule;
|
|
|
|
|
use Domain\Models\ValueObjects\OrderEmployee;
|
2026-10-02 12:14:48 +02:00
|
|
|
use Domain\Models\ValueObjects\ShopperEstablishmentCode;
|
|
|
|
|
use Domain\Models\ValueObjects\ShopperServiceCode;
|
|
|
|
|
use Domain\Models\ValueObjects\ShopperSiteCode;
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
describe('OrderEmployee', function (): void {
|
|
|
|
|
it('can instantiate correctly', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$matricule = new Matricule('1234567');
|
2026-10-02 12:14:48 +02:00
|
|
|
$facility = new ShopperEstablishmentCode('ETAB01');
|
|
|
|
|
$site = new ShopperSiteCode('SITEA');
|
|
|
|
|
$service = new ShopperServiceCode('101');
|
|
|
|
|
|
|
|
|
|
// WHEN
|
2026-06-14 21:32:07 +02:00
|
|
|
$employee = new OrderEmployee(
|
|
|
|
|
$matricule,
|
|
|
|
|
'John',
|
|
|
|
|
'Doe',
|
2026-10-02 12:14:48 +02:00
|
|
|
$facility,
|
|
|
|
|
$site,
|
|
|
|
|
$service
|
2026-06-14 21:32:07 +02:00
|
|
|
);
|
|
|
|
|
|
2026-10-02 12:14:48 +02:00
|
|
|
// THEN
|
2026-06-14 21:32:07 +02:00
|
|
|
expect($employee->matricule)->toBe($matricule)
|
|
|
|
|
->and($employee->firstname)->toBe('John')
|
|
|
|
|
->and($employee->lastname)->toBe('Doe')
|
2026-10-02 12:14:48 +02:00
|
|
|
->and($employee->facility)->toBe($facility)
|
|
|
|
|
->and($employee->site)->toBe($site)
|
|
|
|
|
->and($employee->service)->toBe($service);
|
2026-06-14 21:32:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('throws exception if firstname is empty', function (): void {
|
|
|
|
|
// GIVEN
|
2026-10-02 12:14:48 +02:00
|
|
|
$matricule = new Matricule('1234567');
|
|
|
|
|
$facility = new ShopperEstablishmentCode('ETAB01');
|
|
|
|
|
$site = new ShopperSiteCode('SITEA');
|
|
|
|
|
$service = new ShopperServiceCode('101');
|
|
|
|
|
|
2026-06-14 21:32:07 +02:00
|
|
|
// WHEN
|
2026-10-02 12:14:48 +02:00
|
|
|
$action = fn () => new OrderEmployee($matricule, '', 'Doe', $facility, $site, $service);
|
|
|
|
|
|
2026-06-14 21:32:07 +02:00
|
|
|
// THEN
|
|
|
|
|
expect($action)->toThrow(\DomainException::class, 'firstname cannot be empty');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('throws exception if lastname is empty', function (): void {
|
|
|
|
|
// GIVEN
|
2026-10-02 12:14:48 +02:00
|
|
|
$matricule = new Matricule('1234567');
|
|
|
|
|
$facility = new ShopperEstablishmentCode('ETAB01');
|
|
|
|
|
$site = new ShopperSiteCode('SITEA');
|
|
|
|
|
$service = new ShopperServiceCode('101');
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
// WHEN
|
2026-10-02 12:14:48 +02:00
|
|
|
$action = fn () => new OrderEmployee($matricule, 'John', '', $facility, $site, $service);
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
// THEN
|
2026-10-02 12:14:48 +02:00
|
|
|
expect($action)->toThrow(\DomainException::class, 'lastname cannot be empty');
|
2026-06-14 21:32:07 +02:00
|
|
|
});
|
|
|
|
|
});
|