132 lines
5.7 KiB
PHP
132 lines
5.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Entities\Inco;
|
|
|
|
use Domain\Builders\Inco\IncoCompositionBuilder;
|
|
use Domain\Models\Entities\Inco\Composition\IncoComposition;
|
|
use Domain\Models\ValueObjects\Inco\Composition\AminoAcids;
|
|
use Domain\Models\ValueObjects\Inco\Composition\CarbohydratesDetail;
|
|
use Domain\Models\ValueObjects\Inco\Composition\Energy;
|
|
use Domain\Models\ValueObjects\Inco\Composition\EnergyValues;
|
|
use Domain\Models\ValueObjects\Inco\Composition\FattyAcids;
|
|
use Domain\Models\ValueObjects\Inco\Composition\FreshProduceAndNuts;
|
|
use Domain\Models\ValueObjects\Inco\Composition\FruitAndNutAmount;
|
|
use Domain\Models\ValueObjects\Inco\Composition\Identification;
|
|
use Domain\Models\ValueObjects\Inco\Composition\IncoCompositionId;
|
|
use Domain\Models\ValueObjects\Inco\Composition\Minerals;
|
|
use Domain\Models\ValueObjects\Inco\Composition\NutrientValue;
|
|
use Domain\Models\ValueObjects\Inco\Composition\NutriScore;
|
|
use Domain\Models\ValueObjects\Inco\Composition\NutriScorePoints;
|
|
use Domain\Models\ValueObjects\Inco\Composition\PercentageValue;
|
|
use Domain\Models\ValueObjects\Inco\Composition\PortionMacronutrients;
|
|
use Domain\Models\ValueObjects\Inco\Composition\ReferenceIntakes;
|
|
use Domain\Models\ValueObjects\Inco\Composition\ReferenceMacronutrients;
|
|
use Domain\Models\ValueObjects\Inco\Composition\SpecialCompounds;
|
|
use Domain\Models\ValueObjects\Inco\Composition\Vitamins;
|
|
use Domain\Models\ValueObjects\Inco\IncoId;
|
|
|
|
covers(IncoCompositionBuilder::class);
|
|
|
|
describe('IncoCompositionBuilder Unit Tests', function (): void {
|
|
it('builds an IncoComposition entity when all fields are provided', function (): void {
|
|
// GIVEN
|
|
$id = new IncoCompositionId('67890');
|
|
$idInco = new IncoId('12345');
|
|
$identification = new Identification('Poulet Rôti', '12345', 'LDC');
|
|
$zeroNutrient = new NutrientValue('0');
|
|
$zeroPercent = new PercentageValue('0');
|
|
|
|
$energyValues = new EnergyValues('100g', '750', '180');
|
|
$energy = new Energy($energyValues, $energyValues);
|
|
|
|
$refMacronutrients = new ReferenceMacronutrients(
|
|
fat: $zeroNutrient,
|
|
saturatedFat: $zeroNutrient,
|
|
carbohydrates: $zeroNutrient,
|
|
sugars: $zeroNutrient,
|
|
fiber: $zeroNutrient,
|
|
protein: $zeroNutrient,
|
|
salt: $zeroNutrient,
|
|
);
|
|
|
|
$portionMacronutrients = new PortionMacronutrients(
|
|
fat: $zeroNutrient,
|
|
saturatedFat: $zeroNutrient,
|
|
carbohydrates: $zeroNutrient,
|
|
sugars: $zeroNutrient,
|
|
fiber: $zeroNutrient,
|
|
protein: $zeroNutrient,
|
|
salt: $zeroNutrient,
|
|
);
|
|
|
|
$fruitNutAmount = new FruitAndNutAmount();
|
|
$freshProduce = new FreshProduceAndNuts(
|
|
reference: $fruitNutAmount,
|
|
portion: $fruitNutAmount,
|
|
freshFnlPercentage: $zeroPercent,
|
|
fruitsPercentage: $zeroPercent,
|
|
);
|
|
|
|
$referenceIntakes = new ReferenceIntakes(
|
|
energyE14: $zeroPercent,
|
|
energyKj: $zeroPercent,
|
|
fat: $zeroPercent,
|
|
saturatedFat: $zeroPercent,
|
|
carbohydrates: $zeroPercent,
|
|
sugars: $zeroPercent,
|
|
protein: $zeroPercent,
|
|
salt: $zeroPercent,
|
|
portionAmount: '100g',
|
|
);
|
|
|
|
$nutriScore = new NutriScore('0', grade: 'D');
|
|
$nutriScorePoints = new NutriScorePoints('0', '0', '0', '0', '0', '0', '0');
|
|
|
|
$minerals = new Minerals('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0');
|
|
$vitamins = new Vitamins('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0');
|
|
$carbohydratesDetail = new CarbohydratesDetail('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0');
|
|
$fattyAcids = new FattyAcids('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0');
|
|
$aminoAcids = new AminoAcids('0', '0', '0');
|
|
$specialCompounds = new SpecialCompounds('0', '0', '0', '0');
|
|
|
|
// WHEN
|
|
$compo = IncoComposition::builder()
|
|
->withId($id)
|
|
->withIdInco($idInco)
|
|
->withIdentification($identification)
|
|
->withEnergy($energy)
|
|
->withReferenceMacronutrients($refMacronutrients)
|
|
->withPortionMacronutrients($portionMacronutrients)
|
|
->withFreshProduceAndNuts($freshProduce)
|
|
->withReferenceIntakes($referenceIntakes)
|
|
->withNutriScore($nutriScore)
|
|
->withNutriScorePoints($nutriScorePoints)
|
|
->withMinerals($minerals)
|
|
->withVitamins($vitamins)
|
|
->withCarbohydratesDetail($carbohydratesDetail)
|
|
->withFattyAcids($fattyAcids)
|
|
->withAminoAcids($aminoAcids)
|
|
->withSpecialCompounds($specialCompounds)
|
|
->build();
|
|
|
|
// THEN
|
|
expect($compo)->toBeInstanceOf(IncoComposition::class)
|
|
->and($compo->id())->toBe($id)
|
|
->and($compo->idInco)->toBe($idInco)
|
|
->and($compo->identification->name)->toBe('Poulet Rôti')
|
|
->and($compo->nutriScore->grade)->toBe('D');
|
|
});
|
|
|
|
it('throws DomainException when required fields are missing', function (): void {
|
|
// GIVEN
|
|
$builder = new IncoCompositionBuilder();
|
|
|
|
// WHEN
|
|
expect(fn () => $builder->build())
|
|
|
|
// THEN
|
|
->toThrow(\DomainException::class, 'Cannot build IncoComposition: missing required components.');
|
|
});
|
|
});
|