ldc-cocotte/tests/Unit/App/Dto/ProductIncoDtoTest.php

52 lines
2 KiB
PHP

<?php
declare(strict_types=1);
use App\Dto\ProductIncoDto;
use Domain\Enums\Nutriscore;
use Domain\Models\ValueObjects\NutritionalValues;
describe('ProductIncoDto', function () {
test('it can be instantiated with all properties', function () {
// GIVEN
$nutrition = new NutritionalValues(refWeightG: 100.0, kj: 450.0, kcal: 110.0);
// WHEN
$dto = new ProductIncoDto(
id: 42,
no_art: 105,
product_id: '018f6c40-1234-7123-8123-123456789012',
ingredients: 'Volaille, sel',
preparation: 'Au four 30min',
servings: '4 personnes',
allergens: 'Aucun',
selling_argument: 'Origine France',
nutriscore: Nutriscore::A,
nutriscore_args: 'Faible en gras',
nutrition: $nutrition,
);
// THEN
expect($dto->id)->toBe(42)
->and($dto->no_art)->toBe(105)
->and($dto->product_id)->toBe('018f6c40-1234-7123-8123-123456789012')
->and($dto->ingredients)->toBe('Volaille, sel')
->and($dto->preparation)->toBe('Au four 30min')
->and($dto->servings)->toBe('4 personnes')
->and($dto->allergens)->toBe('Aucun')
->and($dto->selling_argument)->toBe('Origine France')
->and($dto->nutriscore)->toBe(Nutriscore::A)
->and($dto->nutriscore_args)->toBe('Faible en gras')
->and($dto->nutrition)->toBe($nutrition)
->and($dto->getRouteKey())->toBe(42)
->and($dto->getRouteKeyName())->toBe('id')
->and($dto->resolveRouteBinding('some-id'))->toBeNull()
->and($dto->resolveChildRouteBinding('child', 'some-id', 'field'))->toBeNull();
$array = $dto->toArray();
expect($array)->toHaveKey('id', 42)
->and($array)->toHaveKey('no_art', 105)
->and($array)->toHaveKey('nutriscore', Nutriscore::A->value)
->and($array['nutrition'])->toHaveKey('nv_ref_weight_g', 100.0);
});
});