feat(factory): update Product and Recipe factories for image paths and nutritional values

- Changed image URL generation to use UUIDs for consistency.
- Updated nutritional values to use new NutritionalValue objects.
This commit is contained in:
Jérémy Munsch 2026-11-05 12:55:37 +01:00
parent 47671eaa6f
commit bb454c3684
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4
2 changed files with 19 additions and 14 deletions

View file

@ -7,7 +7,9 @@ namespace Database\Factories;
use App\Models\Product;
use Domain\Models\ValueObjects\Products\BreedingMethod;
use Domain\Models\ValueObjects\Products\Business;
use Domain\Models\ValueObjects\Products\NutritionalValue;
use Domain\Models\ValueObjects\Products\NutritionalValues;
use Domain\Models\ValueObjects\Products\NutritionnalUnit;
use Domain\Models\ValueObjects\Products\ProductCategory;
use Domain\Models\ValueObjects\Products\ProductFormat;
use Domain\Models\ValueObjects\Products\Technology;
@ -23,7 +25,7 @@ class ProductFactory extends Factory
return [
'seo_title' => $this->faker->sentence(4),
'seo_description' => $this->faker->text(150),
'picture' => $this->faker->imageUrl(800, 600, 'food'),
'picture' => 'products/' . $this->faker->uuid() . '.jpg',
'picture_alt' => $this->faker->words(3, true),
'picture_title' => $this->faker->words(3, true),
@ -57,19 +59,22 @@ class ProductFactory extends Factory
'conservation_after_opening' => $this->faker->optional(0.7)->sentence(),
'nutritional_values' => $this->faker->boolean(80) ? new NutritionalValues(
refWeightG: 100.0,
kj: $this->faker->randomFloat(2, 0, 3000),
kcal: $this->faker->randomFloat(2, 0, 800),
fatG: $this->faker->randomFloat(2, 0, 100),
satFatG: $this->faker->randomFloat(2, 0, 50),
carbG: $this->faker->randomFloat(2, 0, 100),
sugarG: $this->faker->randomFloat(2, 0, 100),
fiberG: $this->faker->randomFloat(2, 0, 50),
proteinG: $this->faker->randomFloat(2, 0, 100),
saltG: $this->faker->randomFloat(2, 0, 10),
refWeightG: new NutritionalValue('100', NutritionnalUnit::GRAM),
kj: new NutritionalValue(
(string) $this->faker->numberBetween(200, 3000),
NutritionnalUnit::KJ
),
kcal: new NutritionalValue((string) $this->faker->numberBetween(50, 800), NutritionnalUnit::KCAL),
fatG: new NutritionalValue((string) $this->faker->randomFloat(1, 0, 100), NutritionnalUnit::GRAM),
satFatG: new NutritionalValue((string) $this->faker->randomFloat(1, 0, 50), NutritionnalUnit::GRAM),
carbG: new NutritionalValue((string) $this->faker->randomFloat(1, 0, 100), NutritionnalUnit::GRAM),
sugarG: new NutritionalValue((string) $this->faker->randomFloat(1, 0, 100), NutritionnalUnit::GRAM),
fiberG: new NutritionalValue((string) $this->faker->randomFloat(1, 0, 50), NutritionnalUnit::GRAM),
proteinG: new NutritionalValue((string) $this->faker->randomFloat(1, 0, 100), NutritionnalUnit::GRAM),
saltG: new NutritionalValue((string) $this->faker->randomFloat(2, 0, 10), NutritionnalUnit::GRAM),
) : null,
'pdf' => $this->faker->optional(0.5)->filePath(),
'pdf' => $this->faker->boolean(50) ? 'products/' . $this->faker->uuid() . '.pdf' : null,
'inco_code' => $this->faker->optional(0.5)->bothify('INCO-####'),
];
}

View file

@ -20,7 +20,7 @@ class RecipeFactory extends Factory
return [
'seo_title' => $this->faker->sentence(4),
'seo_description' => $this->faker->text(150),
'picture' => $this->faker->imageUrl(),
'picture' => 'recipes/' . $this->faker->uuid() . '.jpg',
'picture_alt' => $this->faker->words(3, true),
'picture_title' => $this->faker->words(3, true),
'name' => $this->faker->words(3, true),
@ -30,7 +30,7 @@ class RecipeFactory extends Factory
'season' => $this->faker->randomElement(Season::cases()),
'description' => $this->faker->paragraph(),
'details' => 'Pour ' . $this->faker->numberBetween(1, 10) . " personnes\n"
. 'À réaliser en ' . $this->faker->numberBetween(15, 60) . ' minutes',
. 'À réaliser en ' . $this->faker->numberBetween(15, 60) . ' minutes',
'ingredients_list' => $this->faker->paragraph(),
'preparation_steps' => $this->faker->text(),
'tips_and_advices' => $this->faker->optional()->paragraph(),