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

55 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Infra\Adapters\Mappers;
use Domain\Models\Entities\Inco\IncoShortSheet;
use Infra\Adapters\Mappers\IncoShortMapper;
use PHPUnit\Framework\TestCase;
covers(IncoShortMapper::class);
uses(TestCase::class);
describe('IncoShortMapper', function (): void {
it('maps an array row to IncoShortSheet entity', function (): void {
// GIVEN
$row = [
'NO_ART' => 1000101,
'DENOM_LEG' => 'Poulet Rôti 1kg',
'DESCRIPTIF' => 'Délicieux poulet rôti cuit au four',
'DAT_CRE' => '2024-01-15',
'DAT_MAJ' => '2024-06-20',
];
// WHEN
$entity = IncoShortMapper::toDomain($row);
// THEN
expect($entity)->toBeInstanceOf(IncoShortSheet::class)
->and((string) $entity->id->value)->toBe('1000101')
->and($entity->name)->toBe('Délicieux poulet rôti cuit au four.')
->and($entity->label)->toBe('Poulet Rôti 1Kg')
->and($entity->description)->toBe('Délicieux poulet rôti cuit au four.')
->and($entity->createdAt?->format('Y-m-d'))->toBe('2024-01-15')
->and($entity->updatedAt?->format('Y-m-d'))->toBe('2024-06-20');
});
it('maps an object row and derives name when descriptif is missing', function (): void {
// GIVEN
$row = (object) [
'no_art' => '1000102',
'denom_leg' => 'Salade Niçoise au Thon',
];
// WHEN
$entity = IncoShortMapper::toDomain($row);
// THEN
expect($entity)->toBeInstanceOf(IncoShortSheet::class)
->and((string) $entity->id->value)->toBe('1000102')
->and($entity->label)->toBe('Salade Niçoise Au Thon')
->and($entity->description)->toBe('');
});
});