Replace not-found exceptions in Arcadia find/show flows with typed outputs (Found*/NotFoundOutput) and map not-found results in presenters/responses while preserving HTTP 404 problem details. Adjust architecture and unit tests to cover concrete output classes, and remove obsolete Arcadia not-found exception classes and their tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
175 lines
7.1 KiB
PHP
175 lines
7.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Support\Builders;
|
|
|
|
use Application\Arcadia\Usecase\IncoCompositions\Find\FoundIncoCompositionOuput as IncoCompositionOutput;
|
|
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;
|
|
|
|
final class IncoCompositionTestBuilder
|
|
{
|
|
private IncoCompositionId $id;
|
|
|
|
private IncoId $idInco;
|
|
|
|
private Identification $identification;
|
|
|
|
private Energy $energy;
|
|
|
|
private ReferenceMacronutrients $referenceMacronutrients;
|
|
|
|
private PortionMacronutrients $portionMacronutrients;
|
|
|
|
private FreshProduceAndNuts $freshProduceAndNuts;
|
|
|
|
private ReferenceIntakes $referenceIntakes;
|
|
|
|
private NutriScore $nutriScore;
|
|
|
|
private NutriScorePoints $nutriScorePoints;
|
|
|
|
private Minerals $minerals;
|
|
|
|
private Vitamins $vitamins;
|
|
|
|
private CarbohydratesDetail $carbohydratesDetail;
|
|
|
|
private FattyAcids $fattyAcids;
|
|
|
|
private AminoAcids $aminoAcids;
|
|
|
|
private SpecialCompounds $specialCompounds;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->id = new IncoCompositionId('67890');
|
|
$this->idInco = new IncoId('12345');
|
|
$this->identification = new Identification('Poulet Rôti Test', '12345', 'LDC');
|
|
|
|
$energyValues = new EnergyValues('100g', '750', '180');
|
|
$this->energy = new Energy($energyValues, $energyValues);
|
|
|
|
$zeroNutrient = new NutrientValue('0');
|
|
$this->referenceMacronutrients = new ReferenceMacronutrients($zeroNutrient, $zeroNutrient, $zeroNutrient, $zeroNutrient, $zeroNutrient, $zeroNutrient, $zeroNutrient);
|
|
$this->portionMacronutrients = new PortionMacronutrients($zeroNutrient, $zeroNutrient, $zeroNutrient, $zeroNutrient, $zeroNutrient, $zeroNutrient, $zeroNutrient);
|
|
|
|
$fnAmount = new FruitAndNutAmount();
|
|
$zeroPercent = new PercentageValue('0');
|
|
$this->freshProduceAndNuts = new FreshProduceAndNuts($fnAmount, $fnAmount, $zeroPercent, $zeroPercent);
|
|
|
|
$this->referenceIntakes = new ReferenceIntakes($zeroPercent, $zeroPercent, $zeroPercent, $zeroPercent, $zeroPercent, $zeroPercent, $zeroPercent, $zeroPercent, '100g');
|
|
$this->nutriScore = new NutriScore('0', '0', 'A');
|
|
$this->nutriScorePoints = new NutriScorePoints('0', '0', '0', '0', '0', '0', '0');
|
|
|
|
$this->minerals = new Minerals('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0');
|
|
$this->vitamins = new Vitamins('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0');
|
|
$this->carbohydratesDetail = new CarbohydratesDetail('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0');
|
|
$this->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');
|
|
$this->aminoAcids = new AminoAcids('0', '0', '0');
|
|
$this->specialCompounds = new SpecialCompounds('0', '0', '0', '0');
|
|
}
|
|
|
|
public static function create(): self
|
|
{
|
|
return new self();
|
|
}
|
|
|
|
public function withId(string | IncoCompositionId $id): self
|
|
{
|
|
$this->id = is_string($id) ? new IncoCompositionId($id) : $id;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function withIdInco(string | IncoId $idInco): self
|
|
{
|
|
$this->idInco = is_string($idInco) ? new IncoId($idInco) : $idInco;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function withIdentification(string $name, ?string $number = null, ?string $source = null): self
|
|
{
|
|
$this->identification = new Identification(
|
|
name: $name,
|
|
number: $number ?? $this->idInco->value,
|
|
source: $source ?? 'Arcadia',
|
|
);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function withNutriScore(string $grade, string $score = '0', string $negativeComponent = '0'): self
|
|
{
|
|
$this->nutriScore = new NutriScore($negativeComponent, $score, $grade);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function build(): IncoComposition
|
|
{
|
|
return IncoComposition::hydrate(
|
|
id: $this->id,
|
|
idInco: $this->idInco,
|
|
identification: $this->identification,
|
|
energy: $this->energy,
|
|
referenceMacronutrients: $this->referenceMacronutrients,
|
|
portionMacronutrients: $this->portionMacronutrients,
|
|
freshProduceAndNuts: $this->freshProduceAndNuts,
|
|
referenceIntakes: $this->referenceIntakes,
|
|
nutriScore: $this->nutriScore,
|
|
nutriScorePoints: $this->nutriScorePoints,
|
|
minerals: $this->minerals,
|
|
vitamins: $this->vitamins,
|
|
carbohydratesDetail: $this->carbohydratesDetail,
|
|
fattyAcids: $this->fattyAcids,
|
|
aminoAcids: $this->aminoAcids,
|
|
specialCompounds: $this->specialCompounds,
|
|
);
|
|
}
|
|
|
|
public function buildOutput(): IncoCompositionOutput
|
|
{
|
|
$entity = $this->build();
|
|
|
|
return new IncoCompositionOutput(
|
|
id: $entity->id(),
|
|
idInco: $entity->idInco,
|
|
identification: $entity->identification,
|
|
energy: $entity->energy,
|
|
referenceMacronutrients: $entity->referenceMacronutrients,
|
|
portionMacronutrients: $entity->portionMacronutrients,
|
|
freshProduceAndNuts: $entity->freshProduceAndNuts,
|
|
referenceIntakes: $entity->referenceIntakes,
|
|
nutriScore: $entity->nutriScore,
|
|
nutriScorePoints: $entity->nutriScorePoints,
|
|
minerals: $entity->minerals,
|
|
vitamins: $entity->vitamins,
|
|
carbohydratesDetail: $entity->carbohydratesDetail,
|
|
fattyAcids: $entity->fattyAcids,
|
|
aminoAcids: $entity->aminoAcids,
|
|
specialCompounds: $entity->specialCompounds,
|
|
);
|
|
}
|
|
}
|