ldc-arcadia-api/tests/Unit/Infra/Adapters/Mappers/IncoCompositionMapperTest.php

65 lines
2.3 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace Tests\Unit\Infra\Adapters\Mappers;
use Domain\Models\Entities\Inco\Composition\IncoComposition;
use Infra\Adapters\Mappers\IncoCompositionMapper;
use PHPUnit\Framework\TestCase;
covers(IncoCompositionMapper::class);
uses(TestCase::class);
describe('IncoCompositionMapper', function (): void {
it('maps an array row to IncoComposition entity', function (): void {
$row = [
'ID' => 96504,
'ID_INCO' => 47789,
'NOM' => 'NUGGETS DE POULET DU VOLAILLER LE GAULOIS',
'NUMERO' => '96504',
'SOURCE' => '1',
'TAILLE_REF' => '100g',
'VAL_ENERG_KJ_R' => 890,
'VAL_ENERG_KCAL_R' => 212,
'MAT_GRASS_R' => 9.5,
'AGS_R' => 1.8,
'GLUCIDES_R' => 16.0,
'SUCRE_R' => 0.8,
'FIB_ALIM_R' => 1.5,
'PROTEINE_R' => 15.0,
'SEL_R' => 1.10,
'CLASSEMENT' => 'B',
'COMPOSANTE_N' => 6,
'SCORE_NUTRI' => 1,
];
$entity = IncoCompositionMapper::toDomain($row);
expect($entity)->toBeInstanceOf(IncoComposition::class)
->and((string) $entity->id->value)->toBe('96504')
->and((string) $entity->idInco->value)->toBe('47789')
->and($entity->identification->name)->toBe('NUGGETS DE POULET DU VOLAILLER LE GAULOIS')
->and($entity->energy->reference->energyKcal)->toBe('212')
->and($entity->nutriScore->grade)->toBe('B');
});
it('maps an object row to IncoComposition entity', function (): void {
$row = (object) [
'id' => '124503',
'id_inco' => '47996',
'nom' => 'GESIERS ET FOIES CONFITS LE GAULOIS',
'numero' => '124503',
'source' => '1',
];
$entity = IncoCompositionMapper::toDomain($row);
expect($entity)->toBeInstanceOf(IncoComposition::class)
->and((string) $entity->id->value)->toBe('124503')
->and((string) $entity->idInco->value)->toBe('47996')
->and($entity->identification->name)->toBe('GESIERS ET FOIES CONFITS LE GAULOIS');
});
});