58 lines
1.9 KiB
PHP
58 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Application\Arcadia\Usecase\IncoSheets;
|
|
|
|
use Application\Arcadia\Exceptions\IncoSheetNotFoundException;
|
|
use Application\Arcadia\Usecase\IncoSheets\Find\FindIncoSheet;
|
|
use Application\Arcadia\Usecase\IncoSheets\Find\Input;
|
|
use Application\Arcadia\Usecase\IncoSheets\Find\Output;
|
|
use Domain\Models\ValueObjects\Inco\IncoId;
|
|
use Infra\Adapters\Directories\InMemoryIncoSheetDirectory;
|
|
use Tests\Support\Mothers\IncoSheetMother;
|
|
|
|
covers(
|
|
FindIncoSheet::class,
|
|
Input::class,
|
|
Output::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(Output::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('throws NotFoundException when inco sheet does not exist', function () use ($directory): void {
|
|
// GIVEN
|
|
$incoId = new IncoId('99999');
|
|
$usecase = new FindIncoSheet($directory);
|
|
$input = new Input($incoId);
|
|
|
|
// WHEN & THEN
|
|
expect(fn () => $usecase->execute($input))
|
|
->toThrow(IncoSheetNotFoundException::class, "IncoSheet '99999' not found.");
|
|
});
|
|
});
|