ldc-arcadia-api/tests/Unit/Application/Usecase/Employees/FindEmployeeTest.php
Jérémy Munsch 53b0dd9f1e
feat(employees): implement filtering and sorting for employee retrieval
Added Filter and Sorter classes to handle employee filtering and sorting criteria. Updated FindAllEmployees use case to utilize these new classes for improved employee data retrieval.
2026-08-14 09:30:21 +02:00

76 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Application\Usecase\Employees;
use Application\Exceptions\NotFoundException;
use Application\Usecase\Employees\Find\FindEmployee;
use Application\Usecase\Employees\Find\Input;
use Application\Usecase\Employees\Find\Output;
use Domain\Models\Entities\Employee;
use Domain\Models\ValueObjects\Entities\ArcadiaEmployeeId;
use Domain\Models\ValueObjects\EstablishmentCode;
use Domain\Models\ValueObjects\ServiceId;
use Domain\Models\ValueObjects\SiteId;
use Domain\Ports\Directories\EmployeeDirectory;
covers(FindEmployee::class);
describe('FindEmployee Usecase Unit Tests', function (): void {
it('executes successfully and returns Output when employee exists', function (): void {
// GIVEN
$employeeId = new ArcadiaEmployeeId('01155902');
$input = new Input($employeeId);
$employeeDirectory = \Mockery::mock(EmployeeDirectory::class);
$usecase = new FindEmployee($employeeDirectory);
$employee = new Employee(
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,
);
$employeeDirectory->shouldReceive('find')
->once()
->with($employeeId)
->andReturn($employee);
// 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 (): void {
// GIVEN
$employeeId = new ArcadiaEmployeeId('01155902');
$input = new Input($employeeId);
$employeeDirectory = \Mockery::mock(EmployeeDirectory::class);
$usecase = new FindEmployee($employeeDirectory);
$employeeDirectory->shouldReceive('find')
->once()
->with($employeeId)
->andReturnNull();
// WHEN & THEN
expect(fn () => $usecase->execute($input))
->toThrow(NotFoundException::class, "Employee '01155902' not found.");
});
});