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

79 lines
2.4 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;
2024-01-14 15:52:54 +01:00
use Database\Factories\Traits\FakesMedia;
2023-12-27 22:54:58 +01:00
use Illuminate\Database\Eloquent\Factories\Factory;
2024-03-15 01:19:52 +01:00
use Tests\Feature\Form\FormtemplateFieldRequest;
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
{
2024-01-14 15:52:54 +01:00
use FakesMedia;
2023-12-27 22:54:58 +01:00
/**
* 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' => []],
2024-03-13 15:48:08 +01:00
'from' => $this->faker->dateTimeBetween('+1 week', '+4 weeks')->format('Y-m-d H:i:s'),
'to' => $this->faker->dateTimeBetween('+1 week', '+4 weeks')->format('Y-m-d H:i:s'),
'registration_from' => $this->faker->dateTimeBetween('-2 weeks', 'now')->format('Y-m-d H:i:s'),
'registration_until' => $this->faker->dateTimeBetween('now', '+2 weeks')->format('Y-m-d H:i:s'),
2023-12-31 22:35:13 +01:00
'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-03-15 01:19:52 +01:00
/**
* @param array<int, FormtemplateFieldRequest> $sections
*/
public function fields(array $fields): self
{
return $this->sections([FormtemplateSectionRequest::new()->fields($fields)]);
}
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
}