Skip to content

feat(form): Add InputColor class for HTML <input type="color"> element with attributes and rendering capabilities.#53

Merged
terabytesoftw merged 2 commits intomainfrom
feature_23
Feb 21, 2026
Merged

feat(form): Add InputColor class for HTML <input type="color"> element with attributes and rendering capabilities.#53
terabytesoftw merged 2 commits intomainfrom
feature_23

Conversation

@terabytesoftw
Copy link
Contributor

Pull Request

Q A
Is bugfix?
New feature? ✔️
Breaks BC?

…ement with attributes and rendering capabilities.
@coderabbitai
Copy link

coderabbitai bot commented Feb 21, 2026

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added InputColor form component for HTML color inputs with alpha channel and colorspace support (display-p3, limited-srgb).
  • Tests

    • Comprehensive test coverage for InputColor covering attributes, rendering variations, defaults/providers, immutability, and error cases.
  • Documentation

    • Added changelog entry documenting the new InputColor component and its attributes.

Walkthrough

Adds an InputColor form component (type="color"), two attribute traits (alpha, colorspace), a Colorspace enum, changelog entry, and an extensive PHPUnit test suite validating rendering, attributes, and validation.

Changes

Cohort / File(s) Summary
InputColor Component
src/Form/InputColor.php
New final class InputColor extending BaseInput; sets tag to <input>, default type to color, composes traits for attributes, and renders via buildElement().
Attribute Traits
src/Form/Attribute/HasAlpha.php, src/Form/Attribute/HasColorspace.php
New immutable traits: HasAlpha::alpha(bool): static adds alpha attribute; `HasColorspace::colorspace(string
Colorspace Enum
src/Form/Values/Colorspace.php
New string-backed enum Colorspace with cases DISPLAY_P3 = 'display-p3' and LIMITED_SRGB = 'limited-srgb'.
Test Suite
tests/Form/InputColorTest.php
New comprehensive PHPUnit test class (~50+ tests) covering attribute accessors, rendering (many HTML attributes and enums), immutability, provider/default resolution, templates/wrappers, error cases (invalid colorspace), and toString/translation behaviors.
Documentation
CHANGELOG.md
Changelog entry added documenting the InputColor addition and attributes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A color input hops into view,
Alpha and gamut in a gentle hue.
Enums lined up, tests all in a row,
I nudge the UI with a soft brush of glow.
Little rabbit cheers — render on, rainbow! 🎨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately describes the main change: introducing the InputColor class for HTML color input elements with attributes and rendering.
Description check ✅ Passed The description is directly related to the changeset, confirming it's a new feature with no BC breaks, which aligns with the InputColor implementation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature_23

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Feb 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (313c7a2) to head (9954e0b).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #53   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       158       163    +5     
===========================================
  Files             81        84    +3     
  Lines            376       387   +11     
===========================================
+ Hits             376       387   +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@coderabbitai coderabbitai bot added the enhancement New feature or request label Feb 21, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 313c7a2 and 6d6d04d.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • src/Form/Attribute/HasAlpha.php
  • src/Form/Attribute/HasColorspace.php
  • src/Form/InputColor.php
  • src/Form/Values/Colorspace.php
  • tests/Form/InputColorTest.php
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2026-02-06T21:37:44.509Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 24
File: tests/Form/InputTextTest.php:33-620
Timestamp: 2026-02-06T21:37:44.509Z
Learning: In the ui-awesome/html repository, prefer individual test methods over PHPUnit data providers in test classes. This helps maintainers see exactly how each test behaves without cross-referencing data providers. Apply to all PHP test files under tests. Use separate, descriptively named test methods to cover different inputs/edge cases; retain data providers only if they clearly improve readability or reduce duplication.

Applied to files:

  • tests/Form/InputColorTest.php
📚 Learning: 2026-02-11T14:56:18.277Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 37
File: tests/Form/InputTextTest.php:448-457
Timestamp: 2026-02-11T14:56:18.277Z
Learning: In PHP test files under the repository ui-awesome/html (e.g., tests/Form/InputTextTest.php), it is acceptable to use short variable names (e.g., 2-character names like $id). PHPMD's short-variable rule does not need to be strictly followed in test code. During reviews, allow short names in test files and note that this relaxed style applies to tests, while production code should adhere to the standard variable naming conventions.

Applied to files:

  • tests/Form/InputColorTest.php
📚 Learning: 2026-02-21T01:17:40.877Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 51
File: tests/List/UlTest.php:282-283
Timestamp: 2026-02-21T01:17:40.877Z
Learning: In the ui-awesome/html repository, for PHP tests, ensure that assertion messages in tests/List/UlTest.php for methods named testRenderWith*UsingEnum remain identical to the corresponding non-enum tests (i.e., do not append 'using enum' to the failure message). The reason: the underlying render method treats enum and string inputs the same, so failure output should be uniform. Apply this pattern to all similar test cases under tests/ to maintain consistent failure messages across enum vs non-enum variants.

Applied to files:

  • tests/Form/InputColorTest.php
🧬 Code graph analysis (2)
src/Form/InputColor.php (1)
src/Root/Html.php (1)
  • Html (27-40)
tests/Form/InputColorTest.php (6)
src/Root/Html.php (1)
  • Html (27-40)
src/Form/InputColor.php (1)
  • InputColor (42-84)
tests/Support/Stub/DefaultProvider.php (1)
  • DefaultProvider (17-34)
tests/Support/Stub/DefaultThemeProvider.php (1)
  • DefaultThemeProvider (17-39)
src/Form/Attribute/HasAlpha.php (1)
  • alpha (30-33)
src/Form/Attribute/HasColorspace.php (1)
  • colorspace (42-47)
🪛 PHPMD (2.15.0)
src/Form/Attribute/HasColorspace.php

[error] 44-44: Avoid using static access to class '\UIAwesome\Html\Helper\Validator' in method 'colorspace'. (undefined)

(StaticAccess)


[error] 44-44: Avoid using static access to class '\UIAwesome\Html\Form\Values\Colorspace' in method 'colorspace'. (undefined)

(StaticAccess)

tests/Form/InputColorTest.php

[warning] 46-983: The class InputColorTest has 64 public methods and attributes. Consider reducing the number of public items to less than 45. (undefined)

(ExcessivePublicCount)


[warning] 46-983: The class InputColorTest has 64 non-getter- and setter-methods. Consider refactoring InputColorTest to keep number of methods under 25. (undefined)

(TooManyMethods)


[warning] 46-983: The class InputColorTest has 64 public methods. Consider refactoring InputColorTest to keep number of public methods under 10. (undefined)

(TooManyPublicMethods)


[warning] 46-983: The class InputColorTest has an overall complexity of 64 which is very high. The configured complexity threshold is 50. (undefined)

(ExcessiveClassComplexity)


[error] 46-983: The class InputColorTest has a coupling between objects value of 19. Consider to reduce the number of dependencies under 13. (undefined)

(CouplingBetweenObjects)


[warning] 590-590: Avoid variables with short names like $id. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 601-604: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)

(StaticAccess)


[error] 616-619: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)

(StaticAccess)


[error] 934-940: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)

(StaticAccess)


[error] 950-953: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)

(StaticAccess)


[error] 977-977: Avoid using static access to class '\UIAwesome\Html\Helper\Enum' in method 'testThrowInvalidArgumentExceptionForSettingColorspace'. (undefined)

(StaticAccess)


[error] 977-977: Avoid using static access to class '\UIAwesome\Html\Form\Values\Colorspace' in method 'testThrowInvalidArgumentExceptionForSettingColorspace'. (undefined)

(StaticAccess)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: phpunit / PHP 8.4-windows-2022
  • GitHub Check: phpunit / PHP 8.2-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.5-windows-2022
  • GitHub Check: phpunit / PHP 8.1-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.3-ubuntu-latest
  • GitHub Check: linter / Super Linter
  • GitHub Check: linter / Super Linter
🔇 Additional comments (5)
CHANGELOG.md (1)

40-40: LGTM!

Changelog entry format, issue reference, and phrasing are consistent with all prior entries.

src/Form/Attribute/HasAlpha.php (1)

16-33: LGTM!

alpha is confirmed as a valid boolean attribute for <input type="color"> per MDN/WHATWG. The immutable delegation to setAttribute is correct and consistent with the rest of the trait-based API.

src/Form/Values/Colorspace.php (1)

15-26: LGTM!

The two enum cases correctly reflect the only valid colorspace values for <input type="color">: "limited-srgb" (the default) and "display-p3" (the Display P3 color space).

src/Form/InputColor.php (1)

42-83: LGTM!

The class follows the established pattern for all other InputXxx types. The composed traits correctly cover all attributes valid for <input type="color">, including alpha (boolean, controls opacity), colorspace (color space selector), autocomplete, list, form, tabindex, autofocus, and value.

tests/Form/InputColorTest.php (1)

599-620: ⚠️ Potential issue | 🟠 Major

Global state is leaked if assertions fail — wrap SimpleFactory setup/teardown in try/finally.

Both testRenderWithGlobalDefaultsAreApplied and testRenderWithUserOverridesGlobalDefaults call SimpleFactory::setDefaults() and then reset it at the end. Because PHPUnit assertion failures throw AssertionFailedError, the cleanup calls (lines 616–619 and 950–953) are never reached when an assertion fails. This leaves InputColor::class with stale global defaults, which can cause non-obvious failures in any test that runs afterward.

🔒 Proposed fix — use try/finally in both methods
 public function testRenderWithGlobalDefaultsAreApplied(): void
 {
     SimpleFactory::setDefaults(
         InputColor::class,
         ['class' => 'default-class'],
     );
 
+    try {
         self::assertSame(
             <<<HTML
             <input class="default-class" id="inputcolor" type="color">
             HTML,
             InputColor::tag()
                 ->id('inputcolor')
                 ->render(),
             'Failed asserting that global defaults are applied correctly.',
         );
-
-    SimpleFactory::setDefaults(
-        InputColor::class,
-        [],
-    );
+    } finally {
+        SimpleFactory::setDefaults(
+            InputColor::class,
+            [],
+        );
+    }
 }
 public function testRenderWithUserOverridesGlobalDefaults(): void
 {
     SimpleFactory::setDefaults(
         InputColor::class,
         [
             'class' => 'from-global',
             'id' => 'id-global',
         ],
     );
 
+    try {
         self::assertSame(
             <<<HTML
             <input class="from-global" id="value" type="color">
             HTML,
             InputColor::tag(['id' => 'value'])->render(),
             'Failed asserting that user-defined attributes override global defaults correctly.',
         );
-
-    SimpleFactory::setDefaults(
-        InputColor::class,
-        [],
-    );
+    } finally {
+        SimpleFactory::setDefaults(
+            InputColor::class,
+            [],
+        );
+    }
 }

Also applies to: 932-954

⛔ Skipped due to learnings
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 24
File: tests/Form/InputTextTest.php:33-620
Timestamp: 2026-02-06T21:37:51.711Z
Learning: In the ui-awesome/html repository, prefer individual test methods over PHPUnit data providers in test classes. The maintainer values the ability to see exactly how each test works without needing to cross-reference data providers, even if it results in more methods.
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 24
File: tests/Form/InputTextTest.php:289-300
Timestamp: 2026-02-06T21:37:24.484Z
Learning: In the ui-awesome/html repository, the maintainer prefers not to use defensive cleanup patterns (like try/finally) for global state in tests. Their philosophy is that if one test fails, they all fail anyway, so defensive cleanup is not necessary.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Form/Attribute/HasColorspace.php`:
- Around line 42-47: Add an explicit null guard so null is treated as "remove
the attribute" and not passed into Validator::oneOf: in
HasColorspace::colorspace and the analogous method in HasShadowRootMode, check
if $value === null and immediately return $this->setAttribute('colorspace',
null) (or the corresponding attribute name) before calling Validator::oneOf;
only call Validator::oneOf when $value is non-null.

In `@tests/Form/InputColorTest.php`:
- Around line 970-982: Add a new unit test method testRenderWithColorspaceNull
that verifies calling colorspace('display-p3') followed by colorspace(null)
removes the attribute: create the test to assert
InputColor::tag()->colorspace('display-p3')->colorspace(null)->id('inputcolor')->render()
returns "<input id=\"inputcolor\" type=\"color\">". This exercises
HasColorspace::colorspace()’s null-path and complements
testThrowInvalidArgumentExceptionForSettingColorspace which covers invalid
values.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6d6d04d and 9954e0b.

📒 Files selected for processing (1)
  • tests/Form/InputColorTest.php
🧰 Additional context used
🧠 Learnings (6)
📚 Learning: 2026-02-06T21:37:44.509Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 24
File: tests/Form/InputTextTest.php:33-620
Timestamp: 2026-02-06T21:37:44.509Z
Learning: In the ui-awesome/html repository, prefer individual test methods over PHPUnit data providers in test classes. This helps maintainers see exactly how each test behaves without cross-referencing data providers. Apply to all PHP test files under tests. Use separate, descriptively named test methods to cover different inputs/edge cases; retain data providers only if they clearly improve readability or reduce duplication.

Applied to files:

  • tests/Form/InputColorTest.php
📚 Learning: 2026-02-21T13:17:56.866Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 53
File: src/Form/Attribute/HasColorspace.php:42-47
Timestamp: 2026-02-21T13:17:56.866Z
Learning: In the ui-awesome/html repository, `Validator::oneOf()` from the html-helper package already handles `null` values gracefully by returning early without throwing an exception. Methods that use `Validator::oneOf()` with nullable parameters do not need explicit null guards before calling the validator.

Applied to files:

  • tests/Form/InputColorTest.php
📚 Learning: 2026-02-07T18:51:41.006Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 31
File: src/Form/Mixin/HasLabel.php:195-195
Timestamp: 2026-02-07T18:51:41.006Z
Learning: In the ui-awesome/html repository, explicit boolean comparisons (e.g., `isset($var) === false`) are required instead of negation operators (e.g., `!isset($var)`) due to PHPStan strict rules configuration at the highest level.

Applied to files:

  • tests/Form/InputColorTest.php
📚 Learning: 2026-02-09T11:28:09.334Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 35
File: tests/Provider/Form/CheckedProvider.php:13-14
Timestamp: 2026-02-09T11:28:09.334Z
Learning: In the ui-awesome/html repository, using `str_replace` to adapt shared data provider HTML strings for different input types (e.g., adapting `CheckedProvider` for both `InputCheckboxTest` and `InputRadioTest` by replacing "inputcheckbox-" with "inputradio-" and "checkbox" with "radio") is acceptable and considered clear. Don't suggest refactoring such patterns to avoid string replacement.

Applied to files:

  • tests/Form/InputColorTest.php
📚 Learning: 2026-02-11T14:56:18.277Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 37
File: tests/Form/InputTextTest.php:448-457
Timestamp: 2026-02-11T14:56:18.277Z
Learning: In PHP test files under the repository ui-awesome/html (e.g., tests/Form/InputTextTest.php), it is acceptable to use short variable names (e.g., 2-character names like $id). PHPMD's short-variable rule does not need to be strictly followed in test code. During reviews, allow short names in test files and note that this relaxed style applies to tests, while production code should adhere to the standard variable naming conventions.

Applied to files:

  • tests/Form/InputColorTest.php
📚 Learning: 2026-02-21T01:17:40.877Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 51
File: tests/List/UlTest.php:282-283
Timestamp: 2026-02-21T01:17:40.877Z
Learning: In the ui-awesome/html repository, for PHP tests, ensure that assertion messages in tests/List/UlTest.php for methods named testRenderWith*UsingEnum remain identical to the corresponding non-enum tests (i.e., do not append 'using enum' to the failure message). The reason: the underlying render method treats enum and string inputs the same, so failure output should be uniform. Apply this pattern to all similar test cases under tests/ to maintain consistent failure messages across enum vs non-enum variants.

Applied to files:

  • tests/Form/InputColorTest.php
🧬 Code graph analysis (1)
tests/Form/InputColorTest.php (6)
src/Root/Html.php (1)
  • Html (27-40)
src/Form/InputColor.php (1)
  • InputColor (42-84)
tests/Support/Stub/DefaultProvider.php (1)
  • DefaultProvider (17-34)
tests/Support/Stub/DefaultThemeProvider.php (1)
  • DefaultThemeProvider (17-39)
src/Form/Attribute/HasAlpha.php (1)
  • alpha (30-33)
src/Form/Attribute/HasColorspace.php (1)
  • colorspace (42-47)
🪛 PHPMD (2.15.0)
tests/Form/InputColorTest.php

[warning] 46-999: The class InputColorTest has 65 public methods and attributes. Consider reducing the number of public items to less than 45. (undefined)

(ExcessivePublicCount)


[warning] 46-999: The class InputColorTest has 65 non-getter- and setter-methods. Consider refactoring InputColorTest to keep number of methods under 25. (undefined)

(TooManyMethods)


[warning] 46-999: The class InputColorTest has 65 public methods. Consider refactoring InputColorTest to keep number of public methods under 10. (undefined)

(TooManyPublicMethods)


[warning] 46-999: The class InputColorTest has an overall complexity of 65 which is very high. The configured complexity threshold is 50. (undefined)

(ExcessiveClassComplexity)


[error] 46-999: The class InputColorTest has a coupling between objects value of 19. Consider to reduce the number of dependencies under 13. (undefined)

(CouplingBetweenObjects)


[warning] 590-590: Avoid variables with short names like $id. Configured minimum length is 3. (undefined)

(ShortVariable)


[error] 601-604: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)

(StaticAccess)


[error] 616-619: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)

(StaticAccess)


[error] 934-940: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)

(StaticAccess)


[error] 950-953: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)

(StaticAccess)


[error] 972-972: Avoid using static access to class '\UIAwesome\Html\Form\InputColor' in method 'testReturnNewInstanceWhenSettingAttribute'. (undefined)

(StaticAccess)


[error] 993-993: Avoid using static access to class '\UIAwesome\Html\Helper\Enum' in method 'testThrowInvalidArgumentExceptionForSettingColorspace'. (undefined)

(StaticAccess)


[error] 993-993: Avoid using static access to class '\UIAwesome\Html\Form\Values\Colorspace' in method 'testThrowInvalidArgumentExceptionForSettingColorspace'. (undefined)

(StaticAccess)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: phpunit / PHP 8.3-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.5-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.2-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.4-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.1-ubuntu-latest
  • GitHub Check: mutation / PHP 8.5-ubuntu-latest
  • GitHub Check: phpstan / PHP 8.5-ubuntu-latest
  • GitHub Check: linter / Super Linter
  • GitHub Check: easy-coding-standard / PHP 8.5-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.4-ubuntu-latest
  • GitHub Check: linter / Super Linter
🔇 Additional comments (1)
tests/Form/InputColorTest.php (1)

599-620: ⚠️ Potential issue | 🟠 Major

SimpleFactory::setDefaults cleanup is not protected by try/finally — a failing assertion leaves global state dirty.

In both testRenderWithGlobalDefaultsAreApplied (Lines 599–620) and testRenderWithUserOverridesGlobalDefaults (Lines 932–954), SimpleFactory::setDefaults(InputColor::class, []) is placed after the assertion. If assertSame throws AssertionFailedError, execution halts and the cleanup is skipped. The SimpleFactory is a static registry, so any residual defaults (class => 'default-class', id => 'id-global') leak into all subsequently executed tests in the suite, causing non-deterministic failures.

Wrap the assertion in a try/finally block (or use a tearDown() method):

🛡️ Proposed fix — try/finally guard for testRenderWithGlobalDefaultsAreApplied
  public function testRenderWithGlobalDefaultsAreApplied(): void
  {
      SimpleFactory::setDefaults(
          InputColor::class,
          ['class' => 'default-class'],
      );
 
+     try {
          self::assertSame(
              <<<HTML
              <input class="default-class" id="inputcolor" type="color">
              HTML,
              InputColor::tag()
                  ->id('inputcolor')
                  ->render(),
              'Failed asserting that global defaults are applied correctly.',
          );
+     } finally {
          SimpleFactory::setDefaults(
              InputColor::class,
              [],
          );
+     }
  }

Apply the same pattern to testRenderWithUserOverridesGlobalDefaults (Lines 932–954).

⛔ Skipped due to learnings
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 24
File: tests/Form/InputTextTest.php:289-300
Timestamp: 2026-02-06T21:37:24.484Z
Learning: In the ui-awesome/html repository, the maintainer prefers not to use defensive cleanup patterns (like try/finally) for global state in tests. Their philosophy is that if one test fails, they all fail anyway, so defensive cleanup is not necessary.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/Form/InputColorTest.php`:
- Around line 979-983: The assertion calls $inputColor->colorspace('') which
throws InvalidArgumentException because '' is not a valid Colorspace; change the
test to pass a valid value (e.g. 'display-p3') or null so colorspace(...)
returns a new instance and the assertNotSame is reached (refer to
InputColor::colorspace and HasColorspace::colorspace). Also ensure tests that
call SimpleFactory::setDefaults(...) always clean up by wrapping the
modification and assertions in try/finally blocks (or move cleanup to tearDown)
so SimpleFactory::setDefaults(InputColor::class, []) runs in the finally for
both testRenderWithGlobalDefaultsAreApplied and
testRenderWithUserOverridesGlobalDefaults.

@terabytesoftw terabytesoftw merged commit e97c0da into main Feb 21, 2026
49 checks passed
@terabytesoftw terabytesoftw deleted the feature_23 branch February 21, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant