61 lines
1.4 KiB
PHP
61 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Question;
|
|
use App\Models\QuestionGroup;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* Factory for generating Question test data.
|
|
*
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Question>
|
|
*/
|
|
final class QuestionFactory extends Factory
|
|
{
|
|
protected $model = Question::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'question_group_id' => QuestionGroup::factory(),
|
|
'text' => fake()->sentence(),
|
|
'has_yes' => true,
|
|
'has_no' => true,
|
|
'has_na' => true,
|
|
'details' => null,
|
|
'sort_order' => fake()->numberBetween(0, 10),
|
|
'is_scored' => true,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Indicate that the question is not scored.
|
|
*/
|
|
public function nonScored(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'is_scored' => false,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Indicate that the question is text-only (no yes/no/na options).
|
|
*/
|
|
public function textOnly(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'has_yes' => false,
|
|
'has_no' => false,
|
|
'has_na' => false,
|
|
'is_scored' => false,
|
|
'details' => 'required',
|
|
]);
|
|
}
|
|
}
|