adrema/database/factories/Form/Models/FormFactory.php

67 lines
2.0 KiB
PHP
Raw Normal View History

2023-12-27 22:54:58 +01:00
<?php
2023-12-31 22:35:13 +01:00
namespace Database\Factories\Form\Models;
2023-12-27 22:54:58 +01:00
use App\Form\Models\Form;
use Illuminate\Database\Eloquent\Factories\Factory;
2024-01-01 16:43:40 +01:00
use Tests\Feature\Form\FormtemplateSectionRequest;
2023-12-27 22:54:58 +01:00
/**
2023-12-31 21:02:40 +01:00
* @extends Factory<Form>
2023-12-31 22:35:13 +01:00
* @method self name(string $name)
* @method self from(string $from)
* @method self to(string $to)
2024-01-10 21:31:34 +01:00
* @method self mailTop(string $content)
* @method self mailBottom(string $content)
2023-12-31 22:35:13 +01:00
* @method self excerpt(string $excerpt)
* @method self description(string $description)
2024-01-10 21:54:35 +01:00
* @method self registrationFrom(string|null $date)
* @method self registrationUntil(string|null $date)
2023-12-27 22:54:58 +01:00
*/
class FormFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
2023-12-31 21:02:40 +01:00
* @var class-string<Form>
2023-12-27 22:54:58 +01:00
*/
protected $model = Form::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
2023-12-31 22:35:13 +01:00
'name' => $this->faker->words(4, true),
'description' => $this->faker->text(),
'excerpt' => $this->faker->words(10, true),
'config' => ['sections' => []],
'from' => $this->faker->dateTime()->format('Y-m-d H:i:s'),
'to' => $this->faker->dateTime()->format('Y-m-d H:i:s'),
'registration_from' => $this->faker->dateTime()->format('Y-m-d H:i:s'),
'registration_until' => $this->faker->dateTime()->format('Y-m-d H:i:s'),
'mail_top' => $this->faker->text(),
'mail_bottom' => $this->faker->text(),
2023-12-27 22:54:58 +01:00
];
}
2023-12-31 22:35:13 +01:00
/**
* @param array<int, FormtemplateSectionRequest> $sections
*/
public function sections(array $sections): self
{
2024-01-10 22:14:27 +01:00
return $this->state(['config' => ['sections' => array_map(fn ($section) => $section->create(), $sections)]]);
2023-12-31 22:35:13 +01:00
}
/**
2024-01-10 21:31:34 +01:00
* @param mixed $parameters
2023-12-31 22:35:13 +01:00
*/
public function __call($method, $parameters): self
{
return $this->state([str($method)->snake()->toString() => $parameters[0]]);
}
2023-12-27 22:54:58 +01:00
}