2026-08-14 11:33:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-08-17 11:18:53 +02:00
|
|
|
namespace Tests\Unit\Application\Arcadia\Usecase\IncoSheets;
|
2026-08-14 11:33:05 +02:00
|
|
|
|
2026-08-18 12:09:35 +02:00
|
|
|
use Application\Arcadia\Exceptions\IncoSheetNotFoundException;
|
2026-08-17 11:18:53 +02:00
|
|
|
use Application\Arcadia\Usecase\IncoSheets\Find\FindIncoSheet;
|
|
|
|
|
use Application\Arcadia\Usecase\IncoSheets\Find\Input;
|
|
|
|
|
use Application\Arcadia\Usecase\IncoSheets\Find\Output;
|
2026-08-14 15:38:10 +02:00
|
|
|
use Domain\Models\ValueObjects\Inco\IncoId;
|
2026-08-18 11:46:43 +02:00
|
|
|
use Infra\Adapters\Directories\InMemoryIncoSheetDirectory;
|
2026-08-21 10:13:43 +02:00
|
|
|
use Tests\Support\Mothers\IncoSheetMother;
|
2026-08-14 11:33:05 +02:00
|
|
|
|
2026-08-18 11:46:43 +02:00
|
|
|
covers(
|
|
|
|
|
FindIncoSheet::class,
|
|
|
|
|
Input::class,
|
|
|
|
|
Output::class,
|
|
|
|
|
);
|
2026-08-14 11:33:05 +02:00
|
|
|
|
|
|
|
|
describe('FindIncoSheet Usecase Unit Tests', function (): void {
|
2026-08-18 11:46:43 +02:00
|
|
|
$directory = new InMemoryIncoSheetDirectory();
|
|
|
|
|
|
|
|
|
|
beforeEach(function () use ($directory): void {
|
|
|
|
|
$directory->clear();
|
|
|
|
|
});
|
2026-08-14 11:33:05 +02:00
|
|
|
|
2026-08-18 11:46:43 +02:00
|
|
|
it('executes successfully and returns Output when inco sheet exists', function () use ($directory): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$incoId = new IncoId('12345');
|
2026-08-21 10:13:43 +02:00
|
|
|
$incoSheet = IncoSheetMother::create(id: '12345', name: 'Poulet Rôti 1kg');
|
2026-08-14 11:33:05 +02:00
|
|
|
|
2026-08-18 11:46:43 +02:00
|
|
|
$directory->add($incoSheet);
|
|
|
|
|
$usecase = new FindIncoSheet($directory);
|
|
|
|
|
$input = new Input($incoId);
|
2026-08-14 11:33:05 +02:00
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$result = $usecase->execute($input);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($result)->toBeInstanceOf(Output::class)
|
2026-08-21 10:13:43 +02:00
|
|
|
->and($result->id->value)->toBe('12345')
|
2026-08-14 11:33:05 +02:00
|
|
|
->and($result->name)->toBe('Poulet Rôti 1kg')
|
2026-08-20 18:16:31 +02:00
|
|
|
->and($result->brand->name->value)->toBe('Le Gaulois')
|
2026-08-21 10:13:43 +02:00
|
|
|
->and($result->brand->code->value)->toBe('LGL01');
|
2026-08-14 11:33:05 +02:00
|
|
|
});
|
|
|
|
|
|
2026-08-18 11:46:43 +02:00
|
|
|
it('throws NotFoundException when inco sheet does not exist', function () use ($directory): void {
|
2026-08-14 11:33:05 +02:00
|
|
|
// GIVEN
|
2026-08-18 11:46:43 +02:00
|
|
|
$incoId = new IncoId('99999');
|
|
|
|
|
$usecase = new FindIncoSheet($directory);
|
|
|
|
|
$input = new Input($incoId);
|
2026-08-14 11:33:05 +02:00
|
|
|
|
|
|
|
|
// WHEN & THEN
|
|
|
|
|
expect(fn () => $usecase->execute($input))
|
2026-08-18 12:09:35 +02:00
|
|
|
->toThrow(IncoSheetNotFoundException::class, "IncoSheet '99999' not found.");
|
2026-08-14 11:33:05 +02:00
|
|
|
});
|
|
|
|
|
});
|