From 018a57968232ad0018356525260c96b2354651ec Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sun, 8 Feb 2026 16:51:53 -0300 Subject: [PATCH 1/2] fix(attribute): Update `value()` method in `HasValue` trait to accept boolean values and adjust related tests and data provider. --- CHANGELOG.md | 1 + src/HasValue.php | 7 ++++--- tests/HasValueTest.php | 4 ++-- tests/Provider/ValueProvider.php | 22 +++++++++++++++++++++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8856ca1..4ef5660 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ - Enh #77: Add `Autocomplete` enum and update `AutocompleteProvider` to add test data (@terabytesoftw) - Enh #78: Add `HasPopover`, `HasPopoverTarget`, `HasPopoverTargetAction` traits and `popover()`, `popoverTarget()`, `popoverTargetAction()` methods to manage popover attributes for HTML elements (@terabytesoftw) - Enh #79: Add `HasInputmode` trait and `inputmode()` method to manage `inputmode` attribute for HTML elements (@terabytesoftw) +- Bug #80: Update `value()` method in `HasValue` trait to accept boolean values and adjust related tests and data provider (@terabytesoftw) ## 0.5.2 January 29, 2026 diff --git a/src/HasValue.php b/src/HasValue.php index 3a2fe7a..3e0cc14 100644 --- a/src/HasValue.php +++ b/src/HasValue.php @@ -26,8 +26,8 @@ trait HasValue * * Defines the current value for the element. * - * @param float|int|string|Stringable|UnitEnum|null $value Element value as `int`, `float`, or `string`, or `null` - * to remove the attribute. + * @param bool|float|int|string|Stringable|UnitEnum|null $value Element value as `bool`, `int`, `float`, `string`, + * or `null` to remove the attribute. * * @return static New instance with the updated `value` attribute. * @@ -37,10 +37,11 @@ trait HasValue * $element->value(3.14); * $element->value('text'); * $element->value(SomeEnum::VALUE); + * $element->value(true); * $element->value(null); * ``` */ - public function value(float|int|string|Stringable|UnitEnum|null $value): static + public function value(bool|float|int|string|Stringable|UnitEnum|null $value): static { return $this->addAttribute(Attribute::VALUE, $value); } diff --git a/tests/HasValueTest.php b/tests/HasValueTest.php index 38c8af0..d66a88d 100644 --- a/tests/HasValueTest.php +++ b/tests/HasValueTest.php @@ -62,9 +62,9 @@ public function testReturnNewInstanceWhenSettingValueAttribute(): void */ #[DataProviderExternal(ValueProvider::class, 'values')] public function testSetValueAttributeValue( - float|int|string|Stringable|UnitEnum|null $value, + bool|float|int|string|Stringable|UnitEnum|null $value, array $attributes, - float|int|string|Stringable|UnitEnum $expectedValue, + bool|float|int|string|Stringable|UnitEnum $expectedValue, string $expectedRenderAttributes, string $message, ): void { diff --git a/tests/Provider/ValueProvider.php b/tests/Provider/ValueProvider.php index 4edf266..abd57f8 100644 --- a/tests/Provider/ValueProvider.php +++ b/tests/Provider/ValueProvider.php @@ -21,7 +21,13 @@ final class ValueProvider /** * @phpstan-return array< * string, - * array{float|int|string|Stringable|UnitEnum|null, mixed[], float|int|string|Stringable|UnitEnum, string, string} + * array{ + * bool|float|int|string|Stringable|UnitEnum|null, + * mixed[], + * bool|float|int|string|Stringable|UnitEnum, + * string, + * string, + * }, * > */ public static function values(): array @@ -34,6 +40,20 @@ public function __toString(): string }; return [ + 'boolean false' => [ + false, + [], + false, + '', + 'Should return the attribute value after setting it.', + ], + 'boolean true' => [ + true, + [], + true, + ' value', + 'Should return the attribute value after setting it.', + ], 'empty string' => [ '', [], From 245c0369b8852876611a539ba3e8ec72bd4fdbad Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sun, 8 Feb 2026 17:00:06 -0300 Subject: [PATCH 2/2] Apply fixed Coderabbitai review. --- src/HasValue.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/HasValue.php b/src/HasValue.php index 3e0cc14..41c07d5 100644 --- a/src/HasValue.php +++ b/src/HasValue.php @@ -26,11 +26,6 @@ trait HasValue * * Defines the current value for the element. * - * @param bool|float|int|string|Stringable|UnitEnum|null $value Element value as `bool`, `int`, `float`, `string`, - * or `null` to remove the attribute. - * - * @return static New instance with the updated `value` attribute. - * * Usage example: * ```php * $element->value(3); @@ -40,6 +35,11 @@ trait HasValue * $element->value(true); * $element->value(null); * ``` + * + * @param bool|float|int|string|Stringable|UnitEnum|null $value Element value as `bool`, `int`, `float`, `string`, + * `Stringable`, `UnitEnum`, or `null` to remove the attribute. + * + * @return static New instance with the updated `value` attribute. */ public function value(bool|float|int|string|Stringable|UnitEnum|null $value): static {