215 lines
6.1 KiB
PHP
215 lines
6.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Support\Builders;
|
|
|
|
use Application\Arcadia\Usecase\IncoSheets\Find\Output as IncoSheetOutput;
|
|
use Domain\Models\Entities\Inco\IncoSheet;
|
|
use Domain\Models\ValueObjects\Brand\ArcadiaId;
|
|
use Domain\Models\ValueObjects\Brand\BrandCode;
|
|
use Domain\Models\ValueObjects\Brand\BrandName;
|
|
use Domain\Models\ValueObjects\Inco\Additive;
|
|
use Domain\Models\ValueObjects\Inco\Allegations;
|
|
use Domain\Models\ValueObjects\Inco\Allergen;
|
|
use Domain\Models\ValueObjects\Inco\Composition\IncoCompositionId;
|
|
use Domain\Models\ValueObjects\Inco\IncoBrand;
|
|
use Domain\Models\ValueObjects\Inco\IncoId;
|
|
use Domain\Models\ValueObjects\Inco\IncoWeight;
|
|
use Domain\Models\ValueObjects\Inco\Ingredients;
|
|
use Domain\Models\ValueObjects\Inco\Nutriscore;
|
|
use Domain\Models\ValueObjects\Inco\PortionAmount;
|
|
use Domain\Models\ValueObjects\Inco\StorageCondition;
|
|
|
|
final class IncoSheetTestBuilder
|
|
{
|
|
private IncoId $id;
|
|
|
|
private string $name;
|
|
|
|
private string $label;
|
|
|
|
private string $description;
|
|
|
|
private Allegations $allegations;
|
|
|
|
private string $sellArguments;
|
|
|
|
private string $preparationAdvices;
|
|
|
|
private ?string $tips = null;
|
|
|
|
private ?string $sellFamilly = null;
|
|
|
|
private Ingredients $ingredients;
|
|
|
|
private ?PortionAmount $portions = null;
|
|
|
|
/** @var array<Allergen> */
|
|
private array $allergens = [];
|
|
|
|
private IncoBrand $brand;
|
|
|
|
private bool $isSeasonal = false;
|
|
|
|
private ?IncoWeight $weight = null;
|
|
|
|
private ?Nutriscore $nutriscore = null;
|
|
|
|
private ?StorageCondition $storageCondition = null;
|
|
|
|
/** @var array<Additive> */
|
|
private array $additives = [];
|
|
|
|
private ?IncoCompositionId $compo = null;
|
|
|
|
private ?\DateTimeInterface $createdAt = null;
|
|
|
|
private ?\DateTimeInterface $updatedAt = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->id = new IncoId('12345');
|
|
$this->name = 'Poulet Rôti 1kg';
|
|
$this->label = 'Poulet Rôti Classe A';
|
|
$this->description = 'Poulet prêt à cuire';
|
|
$this->allegations = new Allegations(['Volaille française']);
|
|
$this->sellArguments = 'Délicieux et tendre';
|
|
$this->preparationAdvices = 'Cuire 45min à 180°C';
|
|
$this->ingredients = new Ingredients(['Ingrédients' => ['Viande de dinde (66%)']]);
|
|
$this->brand = new IncoBrand(new BrandName('Le Gaulois'), new BrandCode('LGL01'), new ArcadiaId(504));
|
|
}
|
|
|
|
public static function create(): self
|
|
{
|
|
return new self();
|
|
}
|
|
|
|
public function withId(string | IncoId $id): self
|
|
{
|
|
$this->id = is_string($id) ? new IncoId($id) : $id;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function withName(string $name): self
|
|
{
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function withLabel(string $label): self
|
|
{
|
|
$this->label = $label;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function withDescription(string $description): self
|
|
{
|
|
$this->description = $description;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function withBrand(IncoBrand | string $brand, ?string $code = null, ?int $arcadiaId = null): self
|
|
{
|
|
if (is_string($brand)) {
|
|
$this->brand = new IncoBrand(
|
|
name: new BrandName($brand),
|
|
code: new BrandCode($code ?? 'LGL01'),
|
|
arcadiaBrandCode: new ArcadiaId($arcadiaId ?? 1),
|
|
);
|
|
} else {
|
|
$this->brand = $brand;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function withNutriscore(?string $grade): self
|
|
{
|
|
$this->nutriscore = $grade !== null ? new Nutriscore($grade) : null;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function withCompo(?string $compoId): self
|
|
{
|
|
$this->compo = $compoId !== null ? new IncoCompositionId($compoId) : null;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function withSeasonal(bool $isSeasonal): self
|
|
{
|
|
$this->isSeasonal = $isSeasonal;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function withDates(?\DateTimeInterface $createdAt, ?\DateTimeInterface $updatedAt = null): self
|
|
{
|
|
$this->createdAt = $createdAt;
|
|
$this->updatedAt = $updatedAt ?? $createdAt;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function build(): IncoSheet
|
|
{
|
|
return IncoSheet::hydrate(
|
|
id: $this->id,
|
|
name: $this->name,
|
|
label: $this->label,
|
|
description: $this->description,
|
|
allegations: $this->allegations,
|
|
sellArguments: $this->sellArguments,
|
|
preparationAdvices: $this->preparationAdvices,
|
|
tips: $this->tips,
|
|
sellFamilly: $this->sellFamilly,
|
|
ingredients: $this->ingredients,
|
|
portions: $this->portions,
|
|
allergens: $this->allergens,
|
|
brand: $this->brand,
|
|
isSeasonal: $this->isSeasonal,
|
|
weight: $this->weight,
|
|
nutriscore: $this->nutriscore,
|
|
storageCondition: $this->storageCondition,
|
|
additives: $this->additives,
|
|
compo: $this->compo,
|
|
createdAt: $this->createdAt,
|
|
updatedAt: $this->updatedAt,
|
|
);
|
|
}
|
|
|
|
public function buildOutput(): IncoSheetOutput
|
|
{
|
|
$entity = $this->build();
|
|
|
|
return new IncoSheetOutput(
|
|
id: $entity->id,
|
|
name: $entity->name,
|
|
label: $entity->label,
|
|
description: $entity->description,
|
|
allegations: $entity->allegations,
|
|
sellArguments: $entity->sellArguments,
|
|
preparationAdvices: $entity->preparationAdvices,
|
|
tips: $entity->tips,
|
|
sellFamilly: $entity->sellFamilly,
|
|
ingredients: $entity->ingredients,
|
|
portions: $entity->portions,
|
|
allergens: $entity->allergens,
|
|
brand: $entity->brand,
|
|
isSeasonal: $entity->isSeasonal,
|
|
weight: $entity->weight,
|
|
nutriscore: $entity->nutriscore,
|
|
storageCondition: $entity->storageCondition,
|
|
additives: $entity->additives,
|
|
compo: $entity->compo,
|
|
createdAt: $entity->createdAt,
|
|
updatedAt: $entity->updatedAt,
|
|
);
|
|
}
|
|
}
|