ldc-ovoteam/database/factories/ProductFactory.php
Jérémy Munsch bb454c3684
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.
2026-11-05 12:55:37 +01:00

81 lines
4 KiB
PHP

<?php
declare(strict_types=1);
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;
use Illuminate\Database\Eloquent\Factories\Factory;
/** @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Product> */
class ProductFactory extends Factory
{
protected $model = Product::class;
public function definition(): array
{
return [
'seo_title' => $this->faker->sentence(4),
'seo_description' => $this->faker->text(150),
'picture' => 'products/' . $this->faker->uuid() . '.jpg',
'picture_alt' => $this->faker->words(3, true),
'picture_title' => $this->faker->words(3, true),
'name' => ucfirst($this->faker->words(3, true)),
'category' => $this->faker->randomElement(ProductCategory::cases()),
'technology' => $this->faker->randomElement(Technology::cases()),
'breeding_methods' => $this->faker->randomElements(
BreedingMethod::cases(),
$this->faker->numberBetween(1, 3)
),
'businesses' => $this->faker->randomElements(
Business::cases(),
$this->faker->numberBetween(1, count(Business::cases()))
),
'is_egalim' => $this->faker->boolean(30),
'formats' => $this->faker->randomElements(
ProductFormat::cases(),
$this->faker->numberBetween(1, 3)
),
'description' => $this->faker->paragraph(),
'details_and_advantages' => $this->faker->paragraphs(2, true),
'handling_advices' => $this->faker->paragraph(),
'ingredients' => $this->faker->optional(0.8)->paragraph(),
'conservation_before_opening' => 'À conserver entre 0°C et 4°C.',
'conservation_after_opening' => $this->faker->optional(0.7)->sentence(),
'nutritional_values' => $this->faker->boolean(80) ? new NutritionalValues(
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->boolean(50) ? 'products/' . $this->faker->uuid() . '.pdf' : null,
'inco_code' => $this->faker->optional(0.5)->bothify('INCO-####'),
];
}
}