88 lines
3.1 KiB
PHP
88 lines
3.1 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\Entities\Inco\IncoSheet;
|
|
use Domain\Models\ValueObjects\Brand\ArcadiaId;
|
|
use Domain\Models\ValueObjects\Brand\BrandCode;
|
|
use Domain\Models\ValueObjects\Brand\BrandName;
|
|
use Domain\Models\ValueObjects\Inco\Allegations;
|
|
use Domain\Models\ValueObjects\Inco\IncoBrand;
|
|
use Domain\Models\ValueObjects\Inco\IncoId;
|
|
use Domain\Models\ValueObjects\Inco\Ingredients;
|
|
use Infra\Adapters\Directories\InMemoryIncoSheetDirectory;
|
|
|
|
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 = IncoSheet::hydrate(
|
|
id: $incoId,
|
|
name: 'Poulet Rôti 1kg',
|
|
label: 'Poulet Rôti Classe A',
|
|
description: 'Poulet prêt à cuire',
|
|
allegations: new Allegations(['Volaille française']),
|
|
sellArguments: 'Délicieux',
|
|
preparationAdvices: 'Cuire 45min à 180°C',
|
|
tips: null,
|
|
sellFamilly: 'Boucherie',
|
|
ingredients: new Ingredients(['Ingrédients' => ['Viande de dinde (66%)']]),
|
|
portions: null,
|
|
allergens: [],
|
|
brand: new IncoBrand(new BrandName('Le Gaulois'), new BrandCode('LGL01'), new ArcadiaId(1)),
|
|
isSeasonal: true,
|
|
weight: null,
|
|
nutriscore: null,
|
|
storageCondition: null,
|
|
additives: [],
|
|
compo: null,
|
|
createdAt: null,
|
|
updatedAt: null,
|
|
);
|
|
|
|
$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)->toBe($incoId)
|
|
->and($result->name)->toBe('Poulet Rôti 1kg')
|
|
->and($result->label)->toBe('Poulet Rôti Classe A')
|
|
->and($result->brand->name->value)->toBe('Le Gaulois')
|
|
->and($result->brand->code->value)->toBe('LGL01')
|
|
->and($result->isSeasonal)->toBeTrue();
|
|
});
|
|
|
|
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.");
|
|
});
|
|
});
|