77 lines
2.6 KiB
PHP
77 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Application\Arcadia\Usecase\Employees;
|
|
|
|
use Application\Arcadia\Exceptions\EmployeeNotFoundException;
|
|
use Application\Arcadia\Usecase\Employees\Find\FindEmployee;
|
|
use Application\Arcadia\Usecase\Employees\Find\Input;
|
|
use Application\Arcadia\Usecase\Employees\Find\Output;
|
|
use Domain\Models\Entities\Employee;
|
|
use Domain\Models\ValueObjects\Employees\SiRhMatricule;
|
|
use Domain\Models\ValueObjects\EstablishmentCode;
|
|
use Domain\Models\ValueObjects\ServiceId;
|
|
use Domain\Models\ValueObjects\SiteId;
|
|
use Infra\Adapters\Directories\InMemoryEmployeeDirectory;
|
|
|
|
covers(
|
|
FindEmployee::class,
|
|
Input::class,
|
|
Output::class,
|
|
);
|
|
|
|
describe('FindEmployee Usecase Unit Tests', function (): void {
|
|
$directory = new InMemoryEmployeeDirectory();
|
|
|
|
beforeEach(function () use ($directory): void {
|
|
$directory->clear();
|
|
});
|
|
|
|
it('executes successfully and returns Output when employee exists', function () use ($directory): void {
|
|
// GIVEN
|
|
$employeeId = new SiRhMatricule('01155902');
|
|
$employee = Employee::hydrate(
|
|
publicEmployeeNumber: $employeeId,
|
|
lastName: 'DOE',
|
|
firstName: 'John',
|
|
startDate: new \DateTimeImmutable('2024-01-01'),
|
|
endDate: null,
|
|
plannedEndDate: null,
|
|
establishment: new EstablishmentCode('EST01'),
|
|
site: new SiteId('LDCSER'),
|
|
service: new ServiceId('097'),
|
|
createdAt: new \DateTimeImmutable('2024-01-01'),
|
|
updatedAt: null,
|
|
);
|
|
|
|
$directory->add($employee);
|
|
$usecase = new FindEmployee($directory);
|
|
$input = new Input($employeeId);
|
|
|
|
// WHEN
|
|
$result = $usecase->execute($input);
|
|
|
|
// THEN
|
|
expect($result)->toBeInstanceOf(Output::class)
|
|
->and($result->id)->toBe($employeeId)
|
|
->and($result->firstName)->toBe('John')
|
|
->and($result->lastName)->toBe('DOE')
|
|
->and($result->establishment)->toBe('EST01')
|
|
->and($result->site)->toBe('LDCSER')
|
|
->and($result->service)->toBe('097');
|
|
});
|
|
|
|
it('throws NotFoundException when employee does not exist', function () use ($directory): void {
|
|
// GIVEN
|
|
$employeeId = new SiRhMatricule('01155902');
|
|
$usecase = new FindEmployee($directory);
|
|
$input = new Input($employeeId);
|
|
|
|
// WHEN
|
|
$execution = fn () => $usecase->execute($input);
|
|
|
|
// THEN
|
|
expect($execution)->toThrow(EmployeeNotFoundException::class, "Employee '01155902' not found.");
|
|
});
|
|
});
|