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>
62 lines
2 KiB
PHP
62 lines
2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Application\Arcadia\Usecase\IncoSheets;
|
|
|
|
use Application\Arcadia\Usecase\IncoSheets\Find\FindIncoSheet;
|
|
use Application\Arcadia\Usecase\IncoSheets\Find\FoundIncoSheetOuput;
|
|
use Application\Arcadia\Usecase\IncoSheets\Find\Input;
|
|
use Application\Arcadia\Usecase\IncoSheets\Find\NotFoundOutput;
|
|
use Domain\Models\ValueObjects\Inco\IncoId;
|
|
use Infra\Adapters\Directories\InMemoryIncoSheetDirectory;
|
|
use Tests\Support\Mothers\IncoSheetMother;
|
|
|
|
covers(
|
|
FindIncoSheet::class,
|
|
Input::class,
|
|
FoundIncoSheetOuput::class,
|
|
NotFoundOutput::class,
|
|
);
|
|
|
|
describe('FindIncoSheet Usecase Unit Tests', function (): void {
|
|
$directory = new InMemoryIncoSheetDirectory();
|
|
|
|
beforeEach(function () use ($directory): void {
|
|
$directory->clear();
|
|
});
|
|
|
|
it('executes successfully and returns Output when inco sheet exists', function () use ($directory): void {
|
|
// GIVEN
|
|
$incoId = new IncoId('12345');
|
|
$incoSheet = IncoSheetMother::create(id: '12345', name: 'Poulet Rôti 1kg');
|
|
|
|
$directory->add($incoSheet);
|
|
$usecase = new FindIncoSheet($directory);
|
|
$input = new Input($incoId);
|
|
|
|
// WHEN
|
|
$result = $usecase->execute($input);
|
|
|
|
// THEN
|
|
expect($result)->toBeInstanceOf(FoundIncoSheetOuput::class)
|
|
->and($result->id->value)->toBe('12345')
|
|
->and($result->name)->toBe('Poulet Rôti 1kg')
|
|
->and($result->brand->name->value)->toBe('Le Gaulois')
|
|
->and($result->brand->code->value)->toBe('LGL01');
|
|
});
|
|
|
|
it('returns NotFoundOutput when inco sheet does not exist', function () use ($directory): void {
|
|
// GIVEN
|
|
$incoId = new IncoId('99999');
|
|
$usecase = new FindIncoSheet($directory);
|
|
$input = new Input($incoId);
|
|
|
|
// WHEN
|
|
$output = $usecase->execute($input);
|
|
|
|
// THEN
|
|
expect($output)->toBeInstanceOf(NotFoundOutput::class)
|
|
->and($output->detail)->toBe("IncoSheet '99999' not found.");
|
|
});
|
|
});
|