Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions app/Support/Converters/DTO/OptionsSchemaField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Support\Converters\DTO;

final readonly class OptionsSchemaField
{
public function __construct(
public string $key,
public string $type,
public string $label,
public mixed $default = null,
public array $options = [],
public bool $required = false,
public ?string $help = null,
) {}

public function toArray(): array
{
return [
'key' => $this->key,
'type' => $this->type,
'label' => $this->label,
'default' => $this->default,
'options' => $this->options,
'required' => $this->required,
'help' => $this->help,
];
}
}
44 changes: 44 additions & 0 deletions tests/Unit/Converters/OptionsSchemaFieldTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

use App\Support\Converters\DTO\OptionsSchemaField;

it('creates options schema field dto', function () {
$field = new OptionsSchemaField(
key: 'quality',
type: 'segmented',
label: 'Quality',
default: 'high',
options: [
['value' => 'medium', 'label' => 'Medium'],
['value' => 'high', 'label' => 'High'],
],
required: false,
);

expect($field->key)->toBe('quality');
expect($field->type)->toBe('segmented');
expect($field->label)->toBe('Quality');
expect($field->default)->toBe('high');
expect($field->options)->toHaveCount(2);
expect($field->required)->toBeFalse();
});

it('exposes toArray representation', function () {
$field = new OptionsSchemaField(
key: 'remove_metadata',
type: 'toggle',
label: 'Remove metadata',
default: false,
help: 'Strips EXIF data',
);

expect($field->toArray())->toBe([
'key' => 'remove_metadata',
'type' => 'toggle',
'label' => 'Remove metadata',
'default' => false,
'options' => [],
'required' => false,
'help' => 'Strips EXIF data',
]);
});