84 lines
3.7 KiB
PHP
84 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Infra\Adapters\Mappers;
|
|
|
|
use Domain\Models\Entities\Inco\IncoSheet;
|
|
use Domain\Models\ValueObjects\Brand\ArcadiaId;
|
|
use Domain\Models\ValueObjects\Brand\BrandName;
|
|
use Domain\Services\BrandResolver;
|
|
use Infra\Adapters\Mappers\IncoMapper;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Domain\Models\Entities\Brand;
|
|
use Domain\Models\ValueObjects\Brand\BrandCode;
|
|
use Domain\Models\ValueObjects\Brand\BrandId;
|
|
use Domain\Services\BrandCodeGenerator;
|
|
use Infra\Adapters\Directories\InMemoryArcadiaBrandDirectory;
|
|
use Infra\Adapters\Repositories\InMemoryBrandRepository;
|
|
use Shared\DDD\Event\DomainEventDispatcher;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
covers(IncoMapper::class);
|
|
|
|
uses(TestCase::class);
|
|
|
|
describe('IncoMapper', function (): void {
|
|
it('maps an array row to complete IncoSheet entity', function (): void {
|
|
$arcadiaDirectory = new InMemoryArcadiaBrandDirectory();
|
|
$brandRepository = new InMemoryBrandRepository();
|
|
$brand = Brand::hydrate(
|
|
id: new BrandId(Uuid::fromString('018e6e5b-1111-7000-8000-000000000001')),
|
|
name: new BrandName('Le Gaulois'),
|
|
code: new BrandCode('LGL01'),
|
|
arcadiaId: new ArcadiaId('1'),
|
|
);
|
|
$brandRepository->add($brand);
|
|
|
|
$brandCodeGenerator = new BrandCodeGenerator();
|
|
$dispatcher = \Mockery::mock(DomainEventDispatcher::class);
|
|
$brandResolver = new BrandResolver($arcadiaDirectory, $brandRepository, $brandCodeGenerator, $dispatcher);
|
|
|
|
$mapper = new IncoMapper($brandResolver);
|
|
|
|
$row = [
|
|
'NO_ART' => 47789,
|
|
'DENOM_LEG' => 'Viande de poulet traitée en salaison, panée et cuite',
|
|
'DESCRIPTIF' => 'Nuggets de poulet du volailler LE GAULOIS',
|
|
'ASTUCES' => 'Pour plus de croustillance, cuisson au Air Fryer',
|
|
'CONSEIL_PREPA' => 'Au four chaud pendant 10 minutes',
|
|
'ARG_VENTE' => 'Une volaille 100% française',
|
|
'ALLEGATIONS' => 'sans conservateur, sans huile de palme',
|
|
'LST_ING' => 'Viande de poulet 51%, eau, panure 30%.',
|
|
'NB_PORTION' => '10',
|
|
'TYP_PORTION' => 'exact',
|
|
'LST_ALLERGENE' => '1:Gluten;7:Lait',
|
|
'MARQUE' => 1,
|
|
'FAMILLE_VTE_LIBELLE' => 'PRODUITS CUITS & PANES',
|
|
'PDS_NET_UVC' => 300.0,
|
|
'PDS_BRUT_UVC' => 320.0,
|
|
'NUTRISCORE_ON_PACK' => 'B',
|
|
'CONDIT_CONSERV' => 'A conserver entre 0°C et +4°C',
|
|
'LST_ADDITIF' => 'E300:Acide ascorbique',
|
|
'PROD_SAISON' => 0,
|
|
'REF_COMPO' => 96504,
|
|
'DAT_CRE' => '2024-01-15',
|
|
'DAT_MAJ' => '2024-06-20',
|
|
];
|
|
|
|
$sheet = $mapper->toDomain($row);
|
|
|
|
expect($sheet)->toBeInstanceOf(IncoSheet::class)
|
|
->and((string) $sheet->id->value)->toBe('47789')
|
|
->and($sheet->name)->toBe('Nuggets de poulet du volailler le gaulois.')
|
|
->and($sheet->label)->toBe('Viande De Poulet Traitée En Salaison, Panée Et Cuite')
|
|
->and($sheet->brand->code->value)->toBe('LGL01')
|
|
->and($sheet->brand->name->value)->toBe('Le Gaulois')
|
|
->and($sheet->sellFamilly)->toBe('Produits cuits & panes')
|
|
->and($sheet->nutriscore?->grade)->toBe('B')
|
|
->and((string) $sheet->compo?->value)->toBe('96504')
|
|
->and($sheet->allergens)->toHaveCount(2)
|
|
->and($sheet->additives)->toHaveCount(1)
|
|
->and($sheet->isSeasonal)->toBeFalse();
|
|
});
|
|
});
|