Replace not-found exceptions in Arcadia find/show flows with typed outputs (Found*/NotFoundOutput) and map not-found results in presenters/responses while preserving HTTP 404 problem details. Adjust architecture and unit tests to cover concrete output classes, and remove obsolete Arcadia not-found exception classes and their tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
79 lines
2.7 KiB
PHP
79 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Application\Arcadia\Usecase\Employees;
|
|
|
|
use Application\Arcadia\Usecase\Employees\Find\FindEmployee;
|
|
use Application\Arcadia\Usecase\Employees\Find\FoundEmployeeOuput;
|
|
use Application\Arcadia\Usecase\Employees\Find\Input;
|
|
use Application\Arcadia\Usecase\Employees\Find\NotFoundOutput;
|
|
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,
|
|
FoundEmployeeOuput::class,
|
|
NotFoundOutput::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(FoundEmployeeOuput::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('returns NotFoundOutput when employee does not exist', function () use ($directory): void {
|
|
// GIVEN
|
|
$employeeId = new SiRhMatricule('01155902');
|
|
$usecase = new FindEmployee($directory);
|
|
$input = new Input($employeeId);
|
|
|
|
// WHEN
|
|
$output = $usecase->execute($input);
|
|
|
|
// THEN
|
|
expect($output)->toBeInstanceOf(NotFoundOutput::class)
|
|
->and($output->detail)->toBe("Employee '01155902' not found.");
|
|
});
|
|
});
|