ldc-cocotte/tests/Unit/Domain/Models/ValueObjects/EmployeeImportTest.php

80 lines
2.7 KiB
PHP
Raw Normal View History

2026-06-14 21:32:07 +02:00
<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\ValueObjects;
use Carbon\CarbonImmutable;
use Domain\Models\ValueObjects\EmployeeImport;
use Domain\Models\ValueObjects\Matricule;
describe('EmployeeImport', function (): void {
it('can instantiate correctly', function (): void {
// GIVEN
$matricule = new Matricule('1234567');
$date = CarbonImmutable::now();
$import = new EmployeeImport(
$matricule,
'Doe',
'John',
'Etab',
'Serv',
'Site',
$date,
null
// WHEN
);
// THEN
expect($import->matricule)->toBe($matricule)
->and($import->nom)->toBe('Doe')
->and($import->prenom)->toBe('John')
->and($import->etablissement)->toBe('Etab')
->and($import->service)->toBe('Serv')
->and($import->site)->toBe('Site')
->and($import->startDate)->toBe($date)
->and($import->endDate)->toBeNull();
});
it('throws exception if nom is empty', function (): void {
// GIVEN
// WHEN
$action = fn () => new EmployeeImport(new Matricule('1234567'), '', 'John', 'Etab', 'Serv', 'Site', CarbonImmutable::now(), null);
// THEN
expect($action)->toThrow(\DomainException::class, 'Name is required');
});
it('throws exception if prenom is empty', function (): void {
// GIVEN
// WHEN
$action = fn () => new EmployeeImport(new Matricule('1234567'), 'Doe', '', 'Etab', 'Serv', 'Site', CarbonImmutable::now(), null);
// THEN
expect($action)->toThrow(\DomainException::class, 'First name is required');
});
it('throws exception if etablissement is empty', function (): void {
// GIVEN
// WHEN
$action = fn () => new EmployeeImport(new Matricule('1234567'), 'Doe', 'John', '', 'Serv', 'Site', CarbonImmutable::now(), null);
// THEN
expect($action)->toThrow(\DomainException::class, 'The establishment is required');
});
it('throws exception if service is empty', function (): void {
// GIVEN
// WHEN
$action = fn () => new EmployeeImport(new Matricule('1234567'), 'Doe', 'John', 'Etab', '', 'Site', CarbonImmutable::now(), null);
// THEN
expect($action)->toThrow(\DomainException::class, 'The service is required');
});
it('throws exception if site is empty', function (): void {
// GIVEN
// WHEN
$action = fn () => new EmployeeImport(new Matricule('1234567'), 'Doe', 'John', 'Etab', 'Serv', '', CarbonImmutable::now(), null);
// THEN
expect($action)->toThrow(\DomainException::class, 'The site is required');
});
});