83 lines
3.4 KiB
PHP
83 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Application\Usecase\Incosheets;
|
|
|
|
use Application\Usecase\IncoSheets\FindAll\FindAllIncoSheets;
|
|
use Application\Usecase\IncoSheets\FindAll\Input;
|
|
use Application\Usecase\IncoSheets\FindAll\Output;
|
|
use Application\Usecase\IncoSheets\FindAll\SortColumn;
|
|
use Application\Usecase\IncoSheets\FindAll\Sorter;
|
|
use Domain\Models\Entities\Inco\IncoSheet;
|
|
use Domain\Models\ValueObjects\Inco\Allegations;
|
|
use Domain\Models\ValueObjects\Inco\Brand;
|
|
use Domain\Models\ValueObjects\Inco\IncoId;
|
|
use Domain\Models\ValueObjects\Inco\IncoSheetSortColumn as DirectoryIncoSheetSortColumn;
|
|
use Domain\Models\ValueObjects\Inco\IncoSheetSorter as DirectoryIncoSheetSorter;
|
|
use Domain\Models\ValueObjects\Inco\Ingredients;
|
|
use Domain\Ports\Directories\IncoSheetDirectory;
|
|
use Domain\Ports\Directories\IncoShortSheetDirectory;
|
|
use Shared\Paginated;
|
|
use Shared\Pagination;
|
|
|
|
covers(FindAllIncoSheets::class);
|
|
|
|
describe('FindAllIncoSheets Usecase Unit Tests', function (): void {
|
|
it('executes successfully and returns paginated output DTO', function (): void {
|
|
// GIVEN
|
|
$pagination = Pagination::ofPage(1, 10);
|
|
$sorter = new Sorter(SortColumn::incoSheetId, \SortDirection::Ascending);
|
|
$input = new Input($pagination, $sorter);
|
|
$incoDirectory = \Mockery::mock(IncoSheetDirectory::class);
|
|
$shortIncoDirectory = \Mockery::mock(IncoShortSheetDirectory::class);
|
|
$usecase = new FindAllIncoSheets($incoDirectory, $shortIncoDirectory);
|
|
|
|
$incoId = new IncoId('12345');
|
|
$incoSheet = new IncoSheet(
|
|
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 Brand('M01', 'Le Gaulois'),
|
|
isSeasonal: true,
|
|
weight: null,
|
|
nutriscore: null,
|
|
storageCondition: null,
|
|
additives: [],
|
|
compo: null,
|
|
createdAt: null,
|
|
updatedAt: null,
|
|
);
|
|
|
|
$paginatedResult = new Paginated($pagination, [$incoSheet], 1);
|
|
$incoDirectory->shouldReceive('findAll')
|
|
->once()
|
|
->withArgs(function (Pagination $actualPagination, DirectoryIncoSheetSorter $actualSorter, mixed $actualFilter) use ($pagination): bool {
|
|
return $actualPagination === $pagination
|
|
&& $actualSorter->sortBy === DirectoryIncoSheetSortColumn::incoSheetId
|
|
&& $actualSorter->direction === \SortDirection::Ascending
|
|
&& $actualFilter === null;
|
|
})
|
|
->andReturn($paginatedResult);
|
|
|
|
// WHEN
|
|
$result = $usecase->execute($input);
|
|
|
|
// THEN
|
|
expect($result)->toBeInstanceOf(Output::class)
|
|
->and($result->total)->toBe(1)
|
|
->and($result->page)->toBe(1)
|
|
->and($result->perPage)->toBe(10)
|
|
->and($result->incoSheets)->toHaveCount(1)
|
|
->and($result->incoSheets[0]->name)->toBe('Poulet Rôti 1kg');
|
|
});
|
|
});
|