adrema/tests/Feature/Form/FormtemplateFieldRequest.php

64 lines
1.7 KiB
PHP
Raw Normal View History

2023-12-26 20:06:57 +01:00
<?php
namespace Tests\Feature\Form;
use App\Form\Fields\Field;
2024-02-16 14:32:16 +01:00
use App\Form\Enums\NamiType;
2023-12-26 20:06:57 +01:00
use Worksome\RequestFactories\RequestFactory;
/**
* @method self name(string $name)
* @method self key(string $key)
* @method self required(string|bool $key)
* @method self rows(int $rows)
* @method self columns(array{mobile: int, tablet: int, desktop: int} $rows)
2023-12-27 00:42:17 +01:00
* @method self default(mixed $default)
2024-02-06 01:24:24 +01:00
* @method self options(array<int, string> $options)
* @method self maxToday(bool $maxToday)
2024-02-09 00:21:33 +01:00
* @method self parentGroup(int $groupId)
* @method self parentField(string $fieldKey)
2024-02-16 14:32:16 +01:00
* @method self namiType(?NamiType $type)
2024-02-19 02:10:58 +01:00
* @method self forMembers(bool $forMembers)
2023-12-26 20:06:57 +01:00
*/
class FormtemplateFieldRequest extends RequestFactory
{
/**
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => $this->faker->words(5, true),
'key' => str($this->faker->words(5, true))->snake()->toString(),
'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6],
2024-02-18 18:48:31 +01:00
'nami_type' => null,
2024-02-18 18:58:28 +01:00
'for_members' => true,
2023-12-26 20:06:57 +01:00
];
}
/**
* @param string|class-string<Field> $field
*/
2024-02-04 03:19:28 +01:00
public static function type(string $field): self
2023-12-26 20:06:57 +01:00
{
2024-02-04 03:19:28 +01:00
2023-12-26 20:06:57 +01:00
if (!$field || !class_exists($field)) {
2024-02-04 03:19:28 +01:00
return self::new(['type' => $field]);
2023-12-26 20:06:57 +01:00
}
2024-02-04 03:19:28 +01:00
return self::new([
2023-12-26 20:06:57 +01:00
'type' => $field::type(),
2024-03-13 15:48:08 +01:00
'value' => $field::default(),
2024-02-04 03:19:28 +01:00
...$field::fake((new static())->faker),
2023-12-26 20:06:57 +01:00
]);
}
/**
* @param mixed $args
*/
public function __call(string $method, $args): self
{
2024-02-06 01:24:09 +01:00
return $this->state([(string) str($method)->snake() => $args[0]]);
2023-12-26 20:06:57 +01:00
}
}