2023-12-26 20:06:57 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Form;
|
|
|
|
|
|
|
|
use App\Form\Fields\Field;
|
|
|
|
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)
|
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],
|
2023-12-27 00:42:17 +01:00
|
|
|
'default' => '',
|
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-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
|
|
|
}
|
|
|
|
}
|