From d597d5ea2b59f6ce1067ada8ac27349fb5de3f88 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Wed, 27 Dec 2023 22:39:23 +0100 Subject: [PATCH] Add fakers for fields --- app/Form/Fields/CheckboxField.php | 5 ++++- app/Form/Fields/CheckboxesField.php | 4 +++- app/Form/Fields/DropdownField.php | 5 ++++- app/Form/Fields/RadioField.php | 5 ++++- app/Form/Fields/TextareaField.php | 5 ++++- tests/Feature/Form/FormtemplateFieldRequest.php | 4 +++- 6 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/Form/Fields/CheckboxField.php b/app/Form/Fields/CheckboxField.php index b0cf687b..a2c8148d 100644 --- a/app/Form/Fields/CheckboxField.php +++ b/app/Form/Fields/CheckboxField.php @@ -26,6 +26,9 @@ class CheckboxField extends Field public static function fake(Generator $faker): array { - return []; + return [ + 'description' => $faker->text(), + 'required' => $faker->boolean(), + ]; } } diff --git a/app/Form/Fields/CheckboxesField.php b/app/Form/Fields/CheckboxesField.php index 45d1546c..8d69a208 100644 --- a/app/Form/Fields/CheckboxesField.php +++ b/app/Form/Fields/CheckboxesField.php @@ -25,6 +25,8 @@ class CheckboxesField extends Field public static function fake(Generator $faker): array { - return []; + return [ + 'options' => $faker->words(4), + ]; } } diff --git a/app/Form/Fields/DropdownField.php b/app/Form/Fields/DropdownField.php index 2c24de5d..7808651d 100644 --- a/app/Form/Fields/DropdownField.php +++ b/app/Form/Fields/DropdownField.php @@ -26,6 +26,9 @@ class DropdownField extends Field public static function fake(Generator $faker): array { - return []; + return [ + 'options' => $faker->words(4), + 'required' => $faker->boolean(), + ]; } } diff --git a/app/Form/Fields/RadioField.php b/app/Form/Fields/RadioField.php index 13af8971..31813824 100644 --- a/app/Form/Fields/RadioField.php +++ b/app/Form/Fields/RadioField.php @@ -26,6 +26,9 @@ class RadioField extends Field public static function fake(Generator $faker): array { - return []; + return [ + 'options' => $faker->words(4), + 'required' => $faker->boolean(), + ]; } } diff --git a/app/Form/Fields/TextareaField.php b/app/Form/Fields/TextareaField.php index 9755677f..1ca8edce 100644 --- a/app/Form/Fields/TextareaField.php +++ b/app/Form/Fields/TextareaField.php @@ -26,6 +26,9 @@ class TextareaField extends Field public static function fake(Generator $faker): array { - return []; + return [ + 'rows' => $faker->numberBetween(5, 10), + 'required' => $faker->boolean(), + ]; } } diff --git a/tests/Feature/Form/FormtemplateFieldRequest.php b/tests/Feature/Form/FormtemplateFieldRequest.php index ad110513..1d735d2b 100644 --- a/tests/Feature/Form/FormtemplateFieldRequest.php +++ b/tests/Feature/Form/FormtemplateFieldRequest.php @@ -22,12 +22,14 @@ class FormtemplateFieldRequest extends RequestFactory */ public function definition(): array { + $type = $this->faker->randomElement(array_column(Field::asMeta(), 'id')); return [ 'name' => $this->faker->words(5, true), 'key' => str($this->faker->words(5, true))->snake()->toString(), - 'type' => $this->faker->randomElement(array_column(Field::asMeta(), 'id')), + 'type' => $type, 'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6], 'default' => '', + ...Field::classFromType($type)::fake($this->faker), ]; }