diff --git a/src/Form/Field.php b/src/Form/Field.php index 13bf88b1b6..7af6c1484f 100644 --- a/src/Form/Field.php +++ b/src/Form/Field.php @@ -279,9 +279,11 @@ public static function factory( ): static|FieldClass { $field = static::$types[$type] ?? null; - if (is_string($field) && class_exists($field) === true) { - $attrs['siblings'] = $siblings; - return new $field($attrs); + if ( + is_string($field) && + is_subclass_of($field, FieldClass::class) === true + ) { + return $field::factory($attrs, $siblings); } return new static($type, $attrs, $siblings); diff --git a/src/Form/Field/BlocksField.php b/src/Form/Field/BlocksField.php index dfadb4a490..f737042e98 100644 --- a/src/Form/Field/BlocksField.php +++ b/src/Form/Field/BlocksField.php @@ -32,20 +32,27 @@ class BlocksField extends FieldClass protected string|null $group; protected mixed $value = []; - public function __construct(array $params = []) - { + public function __construct( + array|string|null $empty = null, + array|string|null $fieldsets = null, + string|null $group = null, + int|null $max = null, + int|null $min = null, + bool $pretty = false, + ...$props + ) { $this->setFieldsets( - $params['fieldsets'] ?? null, - $params['model'] ?? App::instance()->site() + $fieldsets, + $props['model'] ?? App::instance()->site() ); - parent::__construct($params); + parent::__construct(...$props); - $this->setEmpty($params['empty'] ?? null); - $this->setGroup($params['group'] ?? 'blocks'); - $this->setMax($params['max'] ?? null); - $this->setMin($params['min'] ?? null); - $this->setPretty($params['pretty'] ?? false); + $this->setEmpty($empty); + $this->setGroup($group); + $this->setMax($max); + $this->setMin($min); + $this->setPretty($pretty); } public function blocksToValues( @@ -134,7 +141,7 @@ public function isEmpty(): bool public function group(): string { - return $this->group; + return $this->group ?? 'blocks'; } /** diff --git a/src/Form/Field/EntriesField.php b/src/Form/Field/EntriesField.php index 834863366b..376b03b0bc 100644 --- a/src/Form/Field/EntriesField.php +++ b/src/Form/Field/EntriesField.php @@ -34,15 +34,21 @@ class EntriesField extends FieldClass protected Form $form; protected mixed $value = []; - public function __construct(array $params = []) - { - parent::__construct($params); - - $this->setEmpty($params['empty'] ?? null); - $this->setField($params['field'] ?? null); - $this->setMax($params['max'] ?? null); - $this->setMin($params['min'] ?? null); - $this->setSortable($params['sortable'] ?? true); + public function __construct( + array|string|null $empty = null, + array|string|null $field = null, + int|null $max = null, + int|null $min = null, + bool $sortable = true, + ...$props + ) { + parent::__construct(...$props); + + $this->setEmpty($empty); + $this->setField($field); + $this->setMax($max); + $this->setMin($min); + $this->setSortable($sortable); } public function field(): array diff --git a/src/Form/Field/LayoutField.php b/src/Form/Field/LayoutField.php index e920788b3a..8d33ed4a30 100644 --- a/src/Form/Field/LayoutField.php +++ b/src/Form/Field/LayoutField.php @@ -7,6 +7,7 @@ use Kirby\Cms\Fieldset; use Kirby\Cms\Layout; use Kirby\Cms\Layouts; +use Kirby\Cms\ModelWithContent; use Kirby\Data\Data; use Kirby\Data\Json; use Kirby\Exception\InvalidArgumentException; @@ -16,18 +17,21 @@ class LayoutField extends BlocksField { - protected array|null $layouts; - protected array|null $selector; protected Fieldset|null $settings; - public function __construct(array $params) - { - $this->setModel($params['model'] ?? App::instance()->site()); - $this->setLayouts($params['layouts'] ?? ['1/1']); - $this->setSelector($params['selector'] ?? null); - $this->setSettings($params['settings'] ?? null); - - parent::__construct($params); + public function __construct( + protected array $layouts = ['1/1'], + ModelWithContent|null $model = null, + protected array|null $selector = null, + array|string|null $settings = null, + ...$props + ) { + $this->setModel($model ?? App::instance()->site()); + $this->setLayouts($layouts); + $this->setSelector($selector); + $this->setSettings($settings); + + parent::__construct(...$props); } /** diff --git a/src/Form/Field/StatsField.php b/src/Form/Field/StatsField.php index 4d7b8d8a48..f3d42b3fcd 100644 --- a/src/Form/Field/StatsField.php +++ b/src/Form/Field/StatsField.php @@ -17,27 +17,26 @@ */ class StatsField extends FieldClass { - /** - * Array or query string for reports. Each report needs a `label` and `value` and can have additional `info`, `link`, `icon` and `theme` settings. - */ - protected array|string $reports; - - /** - * The size of the report cards. Available sizes: `tiny`, `small`, `medium`, `large` - */ - protected string $size; - /** * Cache for the Stats UI component */ protected Stats $stats; - public function __construct(array $params) - { - parent::__construct($params); - - $this->reports = $params['reports'] ?? []; - $this->size = $params['size'] ?? 'large'; + public function __construct( + /** + * Array or query string for reports. + * Each report needs a `label` and `value` and can have + * additional `info`, `link`, `icon` and `theme` settings. + */ + protected array|string $reports = [], + /** + * The size of the report cards. + * Available sizes: `tiny`, `small`, `medium`, `large` + */ + protected string $size = 'large', + ...$props + ) { + parent::__construct(...$props); } public function hasValue(): bool @@ -58,9 +57,9 @@ public function size(): string public function stats(): Stats { return $this->stats ??= Stats::from( - model: $this->model, + model: $this->model, reports: $this->reports, - size: $this->size + size: $this->size ); } diff --git a/src/Form/FieldClass.php b/src/Form/FieldClass.php index 4f0f9036c6..fcc2da9b6e 100644 --- a/src/Form/FieldClass.php +++ b/src/Form/FieldClass.php @@ -3,6 +3,8 @@ namespace Kirby\Form; use Kirby\Cms\HasSiblings; +use Kirby\Cms\ModelWithContent; +use Kirby\Exception\NotFoundException; use Kirby\Toolkit\HasI18n; /** @@ -39,40 +41,54 @@ abstract class FieldClass use Mixin\When; use Mixin\Width; - protected Fields $siblings; - public function __construct( - protected array $params = [] + array|string|null $after = null, + bool $autofocus = false, + array|string|null $before = null, + mixed $default = null, + bool $disabled = false, + array|string|null $help = null, + string|null $icon = null, + array|string|null $label = null, + ModelWithContent|null $model = null, + string|null $name = null, + array|string|null $placeholder = null, + bool $required = false, + protected Fields|null $siblings = null, + bool $translate = true, + $value = null, + array|null $when = null, + string|null $width = null ) { - $this->setAfter($params['after'] ?? null); - $this->setAutofocus($params['autofocus'] ?? false); - $this->setBefore($params['before'] ?? null); - $this->setDefault($params['default'] ?? null); - $this->setDisabled($params['disabled'] ?? false); - $this->setHelp($params['help'] ?? null); - $this->setIcon($params['icon'] ?? null); - $this->setLabel($params['label'] ?? null); - $this->setModel($params['model'] ?? null); - $this->setName($params['name'] ?? null); - $this->setPlaceholder($params['placeholder'] ?? null); - $this->setRequired($params['required'] ?? false); - $this->setSiblings($params['siblings'] ?? null); - $this->setTranslate($params['translate'] ?? true); - $this->setWhen($params['when'] ?? null); - $this->setWidth($params['width'] ?? null); - - if (array_key_exists('value', $params) === true) { - $this->fill($params['value']); + $this->setAfter($after); + $this->setAutofocus($autofocus); + $this->setBefore($before); + $this->setDefault($default); + $this->setDisabled($disabled); + $this->setHelp($help); + $this->setIcon($icon); + $this->setLabel($label); + $this->setModel($model); + $this->setName($name); + $this->setPlaceholder($placeholder); + $this->setRequired($required); + $this->setSiblings($siblings); + $this->setTranslate($translate); + $this->setWhen($when); + $this->setWidth($width); + + if ($value !== null) { + $this->fill($value); } } public function __call(string $param, array $args): mixed { - if (isset($this->$param) === true) { + if (property_exists($this, $param) === true) { return $this->$param; } - return $this->params[$param] ?? null; + throw new NotFoundException(message: 'Method or option "' . $param . '" does not exist for field type "' . $this->type() . '"'); } /** @@ -91,6 +107,19 @@ public function drawers(): array return []; } + /** + * Creates a new field instance from a $props array + * @since 6.0.0 + */ + public static function factory( + array $props, + Fields|null $siblings = null + ): static { + $props['siblings'] = $siblings; + unset($props['type']); + return new static(...$props); + } + public function id(): string { return $this->name(); @@ -101,14 +130,6 @@ public function isHidden(): bool return false; } - /** - * Returns all original params for the field - */ - public function params(): array - { - return $this->params; - } - /** * Define the props that will be sent to * the Vue component diff --git a/src/Form/Mixin/Validation.php b/src/Form/Mixin/Validation.php index 14df127cd9..74d0668753 100644 --- a/src/Form/Mixin/Validation.php +++ b/src/Form/Mixin/Validation.php @@ -100,6 +100,15 @@ protected function setRequired(bool $required): void $this->required = $required; } + /** + * Runs all validations + * @since 6.0.0 + */ + public function validate(): void + { + $this->errors(); + } + /** * Defines all validation rules */ diff --git a/tests/Form/Field/EntriesFieldTest.php b/tests/Form/Field/EntriesFieldTest.php index b0f34544f4..90de064209 100644 --- a/tests/Form/Field/EntriesFieldTest.php +++ b/tests/Form/Field/EntriesFieldTest.php @@ -363,9 +363,7 @@ public static function validationsProvider(): array public function testValidations($type, $value, $expected): void { $field = $this->field('entries', [ - 'value' => [ - $value - ], + 'value' => [$value], 'field' => $type, 'required' => true ]); diff --git a/tests/Form/FieldClassTest.php b/tests/Form/FieldClassTest.php index 09ddd0d531..3c14f90148 100644 --- a/tests/Form/FieldClassTest.php +++ b/tests/Form/FieldClassTest.php @@ -5,6 +5,7 @@ use Exception; use Kirby\Cms\Language; use Kirby\Cms\Page; +use Kirby\Exception\NotFoundException; use Kirby\TestCase; use PHPUnit\Framework\Attributes\CoversClass; @@ -30,6 +31,13 @@ public function hasValue(): bool class ValidatedField extends FieldClass { + public function __construct( + protected int|null $minlength = null, + ...$props + ) { + parent::__construct(...$props); + } + public function validations(): array { return [ @@ -43,16 +51,26 @@ public function validations(): array } } +class AdditionalPropertyField extends FieldClass +{ + public function __construct( + protected string $foo + ) { + parent::__construct(); + } +} + #[CoversClass(FieldClass::class)] class FieldClassTest extends TestCase { public function test__call(): void { - $field = new TestField([ - 'foo' => 'bar' - ]); - + $field = new AdditionalPropertyField(foo: 'bar'); $this->assertSame('bar', $field->foo()); + + $this->expectException(NotFoundException::class); + $this->expectExceptionMessage('Method or option "bar" does not exist for field type "additionalProperty"'); + $field->bar(); } public function testAfter(): void @@ -60,10 +78,10 @@ public function testAfter(): void $field = new TestField(); $this->assertNull($field->after()); - $field = new TestField(['after' => 'Test']); + $field = new TestField(after: 'Test'); $this->assertSame('Test', $field->after()); - $field = new TestField(['after' => ['en' => 'Test']]); + $field = new TestField(after: ['en' => 'Test']); $this->assertSame('Test', $field->after()); } @@ -78,7 +96,7 @@ public function testAutofocus(): void $field = new TestField(); $this->assertFalse($field->autofocus()); - $field = new TestField(['autofocus' => true]); + $field = new TestField(autofocus: true); $this->assertTrue($field->autofocus()); } @@ -87,10 +105,10 @@ public function testBefore(): void $field = new TestField(); $this->assertNull($field->before()); - $field = new TestField(['before' => 'Test']); + $field = new TestField(before: 'Test'); $this->assertSame('Test', $field->before()); - $field = new TestField(['before' => ['en' => 'Test']]); + $field = new TestField(before: ['en' => 'Test']); $this->assertSame('Test', $field->before()); } @@ -100,15 +118,15 @@ public function testData(): void $this->assertNull($field->data()); // use default value - $field = new TestField(['default' => 'default value']); + $field = new TestField(default: 'default value'); $this->assertSame('default value', $field->data(true)); // don't use default value - $field = new TestField(['default' => 'default value']); + $field = new TestField(default: 'default value'); $this->assertNull($field->data()); // use existing value - $field = new TestField(['value' => 'test']); + $field = new TestField(value: 'test'); $this->assertSame('test', $field->data()); } @@ -118,19 +136,19 @@ public function testDefault(): void $this->assertNull($field->default()); // simple default value - $field = new TestField(['default' => 'Test']); + $field = new TestField(default: 'Test'); $this->assertSame('Test', $field->default()); // default value from string template - $field = new TestField([ - 'model' => new Page([ + $field = new TestField( + model: new Page([ 'slug' => 'test', 'content' => [ 'title' => 'Test title' ] ]), - 'default' => '{{ page.title }}' - ]); + default: '{{ page.title }}' + ); $this->assertSame('Test title', $field->default()); } @@ -147,7 +165,7 @@ public function testDisabled(): void $this->assertFalse($field->disabled()); $this->assertFalse($field->isDisabled()); - $field = new TestField(['disabled' => true]); + $field = new TestField(disabled: true); $this->assertTrue($field->disabled()); $this->assertTrue($field->isDisabled()); } @@ -169,16 +187,16 @@ public function testErrors(): void $field = new TestField(); $this->assertSame([], $field->errors()); - $field = new TestField(['required' => true]); + $field = new TestField(required: true); $this->assertSame(['required' => 'Please enter something'], $field->errors()); - $field = new ValidatedField(['value' => 'a']); + $field = new ValidatedField(value: 'a'); $this->assertSame([], $field->errors()); - $field = new ValidatedField(['value' => 'a', 'minlength' => 4]); + $field = new ValidatedField(value: 'a', minlength: 4); $this->assertSame(['minlength' => 'Please enter a longer value. (min. 4 characters)'], $field->errors()); - $field = new ValidatedField(['value' => 'b']); + $field = new ValidatedField(value: 'b'); $this->assertSame(['custom' => 'Please enter an a'], $field->errors()); } @@ -195,7 +213,7 @@ public function testIsEmpty(): void $field = new TestField(); $this->assertTrue($field->isEmpty()); - $field = new TestField(['value' => 'Test']); + $field = new TestField(value: 'Test'); $this->assertFalse($field->isEmpty()); } @@ -237,10 +255,10 @@ public function testIsTranslatableWithNonDefaultLanguage(): void 'default' => false ]); - $field = new TestField(['translate' => true]); + $field = new TestField(translate: true); $this->assertTrue($field->isTranslatable($language)); - $field = new TestField(['translate' => false]); + $field = new TestField(translate: false); $this->assertFalse($field->isTranslatable($language)); } @@ -249,10 +267,10 @@ public function testInvalid(): void $field = new TestField(); $this->assertFalse($field->isInvalid()); - $field = new TestField(['required' => true]); + $field = new TestField(required: true); $this->assertTrue($field->isInvalid()); - $field = new TestField(['required' => true, 'value' => 'Test']); + $field = new TestField(required: true, value: 'Test'); $this->assertFalse($field->isInvalid()); } @@ -262,7 +280,7 @@ public function testIsRequired(): void $this->assertFalse($field->isRequired()); $this->assertFalse($field->required()); - $field = new TestField(['required' => true]); + $field = new TestField(required: true); $this->assertTrue($field->isRequired()); $this->assertTrue($field->required()); } @@ -282,7 +300,7 @@ public function testIsStorableWithDisabledField(): void { $language = Language::ensure('current'); - $field = new TestField(['disabled' => true]); + $field = new TestField(disabled: true); $this->assertTrue($field->isStorable($language), 'The value of a storable field must not be changed on submit, but can still be stored.'); } @@ -293,10 +311,10 @@ public function testIsStorableWithNonDefaultLanguage(): void 'default' => false ]); - $field = new TestField(['translate' => true]); + $field = new TestField(translate: true); $this->assertTrue($field->isStorable($language)); - $field = new TestField(['translate' => false]); + $field = new TestField(translate: false); $this->assertFalse($field->isStorable($language)); } @@ -315,7 +333,7 @@ public function testIsSubmittableWithDisabledField(): void { $language = Language::ensure('current'); - $field = new TestField(['disabled' => true]); + $field = new TestField(disabled: true); $this->assertTrue($field->isSubmittable($language)); } @@ -326,10 +344,10 @@ public function testIsSubmittableWithNonDefaultLanguage(): void 'default' => false ]); - $field = new TestField(['translate' => true]); + $field = new TestField(translate: true); $this->assertTrue($field->isSubmittable($language)); - $field = new TestField(['translate' => false]); + $field = new TestField(translate: false); $this->assertFalse($field->isSubmittable($language)); } @@ -338,15 +356,13 @@ public function testIsSubmittableWithWhenQueryAndMatchingValue(): void $language = Language::ensure('current'); $siblings = new Fields([ - new TestField(['name' => 'a', 'value' => 'b']), + new TestField(name: 'a', value: 'b'), ]); - $field = new TestField([ - 'siblings' => $siblings, - 'when' => [ - 'a' => 'b' - ], - ]); + $field = new TestField( + siblings: $siblings, + when: ['a' => 'b'] + ); $this->assertTrue($field->isSubmittable($language)); } @@ -356,15 +372,13 @@ public function testIsSubmittableWithWhenQueryAndNonMatchingValue(): void $language = Language::ensure('current'); $siblings = new Fields([ - new TestField(['name' => 'a', 'value' => 'something-else']), + new TestField(name: 'a', value: 'something-else'), ]); - $field = new TestField([ - 'siblings' => $siblings, - 'when' => [ - 'a' => 'b' - ], - ]); + $field = new TestField( + siblings: $siblings, + when: ['a' => 'b'] + ); $this->assertTrue($field->isSubmittable($language)); } @@ -374,20 +388,16 @@ public function testIsSubmittableWithWhenQueryAndTwoFields() $language = Language::ensure('current'); $fields = new Fields([ - new TestField([ - 'name' => 'a', - 'value' => 'a', - 'when' => [ - 'b' => 'b' - ] - ]), - new TestField([ - 'name' => 'b', - 'value' => 'b', - 'when' => [ - 'a' => 'a' - ] - ]), + new TestField( + name: 'a', + value: 'a', + when: ['b' => 'b'] + ), + new TestField( + name: 'b', + value: 'b', + when: ['a' => 'a'] + ), ]); $a = $fields->get('a'); @@ -422,23 +432,23 @@ public function testHelp(): void $this->assertNull($field->help()); // regular help - $field = new TestField(['help' => 'Test']); + $field = new TestField(help: 'Test'); $this->assertSame('

Test

', $field->help()); // translated help - $field = new TestField(['help' => ['en' => 'Test']]); + $field = new TestField(help: ['en' => 'Test']); $this->assertSame('

Test

', $field->help()); // help from string template - $field = new TestField([ - 'model' => new Page([ + $field = new TestField( + model: new Page([ 'slug' => 'test', 'content' => [ 'title' => 'Test title' ] ]), - 'help' => 'A field for {{ page.title }}' - ]); + help: 'A field for {{ page.title }}' + ); $this->assertSame('

A field for Test title

', $field->help()); } @@ -448,7 +458,7 @@ public function testIcon(): void $field = new TestField(); $this->assertNull($field->icon()); - $field = new TestField(['icon' => 'Test']); + $field = new TestField(icon: 'Test'); $this->assertSame('Test', $field->icon()); } @@ -457,7 +467,7 @@ public function testId(): void $field = new TestField(); $this->assertSame('test', $field->id()); - $field = new TestField(['name' => 'test-id']); + $field = new TestField(name: 'test-id'); $this->assertSame('test-id', $field->id()); } @@ -472,10 +482,10 @@ public function testLabel(): void $field = new TestField(); $this->assertSame('Test', $field->label()); - $field = new TestField(['label' => 'Test']); + $field = new TestField(label: 'Test'); $this->assertSame('Test', $field->label()); - $field = new TestField(['label' => ['en' => 'Test']]); + $field = new TestField(label: ['en' => 'Test']); $this->assertSame('Test', $field->label()); } @@ -486,7 +496,7 @@ public function testModel(): void $this->assertIsSite($site, $field->model()); $page = new Page(['slug' => 'test']); - $field = new TestField(['model' => $page]); + $field = new TestField(model: $page); $this->assertIsPage($page, $field->model()); } @@ -495,81 +505,83 @@ public function testName(): void $field = new TestField(); $this->assertSame('test', $field->name()); - $field = new TestField(['name' => 'test-name']); + $field = new TestField(name: 'test-name'); $this->assertSame('test-name', $field->name()); } public function testNameCase(): void { - $field = new TestField(['name' => 'myTest']); + $field = new TestField(name: 'myTest'); $this->assertSame('mytest', $field->name()); } - public function testParams(): void - { - $field = new TestField($params = [ - 'foo' => 'bar', - 'name' => 'Test name', - 'required' => true - ]); - - $this->assertSame($params, $field->params()); - } - public function testPlaceholder(): void { $field = new TestField(); $this->assertNull($field->placeholder()); // regular placeholder - $field = new TestField(['placeholder' => 'Test']); + $field = new TestField(placeholder: 'Test'); $this->assertSame('Test', $field->placeholder()); // translated placeholder - $field = new TestField(['placeholder' => ['en' => 'Test']]); + $field = new TestField(placeholder: ['en' => 'Test']); $this->assertSame('Test', $field->placeholder()); // placeholder from string template - $field = new TestField([ - 'model' => new Page([ + $field = new TestField( + model: new Page([ 'slug' => 'test', 'content' => [ 'title' => 'Test title' ] ]), - 'placeholder' => 'Placeholder for {{ page.title }}' - ]); + placeholder: 'Placeholder for {{ page.title }}' + ); $this->assertSame('Placeholder for Test title', $field->placeholder()); } public function testProps(): void { - $field = new TestField($props = [ - 'after' => 'After value', + $field = new TestField( + after: $after = 'After value', + autofocus: true, + before: $before = 'Before value', + default: $default = 'Default value', + disabled: false, + help: 'Help value', + icon: $icon = 'Icon value', + label: $label = 'Label value', + name: $name = 'name-value', + placeholder: $placeholder = 'Placeholder value', + required: true, + translate: false, + when: $when = ['a' => 'b'], + width: $width = '1/2' + ); + + $array = $field->toArray(); + + $this->assertSame([ + 'after' => $after, 'autofocus' => true, - 'before' => 'Before value', - 'default' => 'Default value', + 'before' => $before, + 'default' => $default, 'disabled' => false, - 'help' => 'Help value', + 'help' => '

Help value

', 'hidden' => false, - 'icon' => 'Icon value', - 'label' => 'Label value', - 'name' => 'name-value', - 'placeholder' => 'Placeholder value', + 'icon' => $icon, + 'label' => $label, + 'name' => $name, + 'placeholder' => $placeholder, 'required' => true, 'saveable' => true, 'translate' => false, 'type' => 'test', - 'when' => ['a' => 'b'], - 'width' => '1/2' - ]); - - $props['help'] = '

Help value

'; - - $array = $field->toArray(); - - $this->assertSame($props, $field->props()); + 'when' => $when, + 'width' => $width + ], $field->props()); } public function testRoutes(): void @@ -591,12 +603,12 @@ public function testSiblings(): void $this->assertCount(1, $field->siblings()); $this->assertSame($field, $field->siblings()->first()); - $field = new TestField([ - 'siblings' => new Fields([ - new TestField(['name' => 'a']), - new TestField(['name' => 'b']), + $field = new TestField( + siblings: new Fields([ + new TestField(name: 'a'), + new TestField(name: 'b'), ]) - ]); + ); $this->assertCount(2, $field->siblings()); $this->assertSame('a', $field->siblings()->first()->name()); @@ -624,7 +636,7 @@ public function testTranslate(): void $field = new TestField(); $this->assertTrue($field->translate()); - $field = new TestField(['translate' => false]); + $field = new TestField(translate: false); $this->assertFalse($field->translate()); } @@ -639,16 +651,16 @@ public function testValue(): void $field = new TestField(); $this->assertNull($field->value()); - $field = new TestField(['value' => 'Test']); + $field = new TestField(value: 'Test'); $this->assertSame('Test', $field->value()); - $field = new TestField(['default' => 'Default value']); + $field = new TestField(default: 'Default value'); $this->assertNull($field->value()); - $field = new TestField(['default' => 'Default value']); + $field = new TestField(default: 'Default value'); $this->assertSame('Default value', $field->value(true)); - $field = new NoValueField(['value' => 'Test']); + $field = new NoValueField(value: 'Test'); $this->assertNull($field->value()); } @@ -657,7 +669,7 @@ public function testWhen(): void $field = new TestField(); $this->assertNull($field->when()); - $field = new TestField(['when' => ['a' => 'test']]); + $field = new TestField(when: ['a' => 'test']); $this->assertSame(['a' => 'test'], $field->when()); } @@ -666,7 +678,7 @@ public function testWidth(): void $field = new TestField(); $this->assertSame('1/1', $field->width()); - $field = new TestField(['width' => '1/2']); + $field = new TestField(width: '1/2'); $this->assertSame('1/2', $field->width()); } }