fix(tests): Refactor tests to use assertSame() for rendering with testRenderWithGlobalDefaultsAreApplied() and testRenderWithUserOverridesGlobalDefaults().#40
Conversation
…testRenderWithGlobalDefaultsAreApplied()` and `testRenderWithGlobalDefaultsAreApplied()`.
📝 WalkthroughWalkthroughThe PR refactors test assertions across 14 form input test files to use exact HTML string matching via heredoc instead of partial string containment checks, and reformats SimpleFactory::setDefaults calls to use multi-line syntax with trailing commas. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #40 +/- ##
===========================================
Coverage 100.00% 100.00%
Complexity 151 151
===========================================
Files 74 74
Lines 378 378
===========================================
Hits 378 378 ☔ View full report in Codecov by Sentry. |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@CHANGELOG.md`:
- Line 28: Update the changelog entry that currently lists the same test method
twice: locate the line mentioning testRenderWithGlobalDefaultsAreApplied() and
replace the duplicate occurrence with the correct test name (e.g.,
testRenderWithUserOverridesGlobalDefaults()) or remove the redundant mention so
the entry reads clearly; ensure the final text reflects the actual refactor
(testRenderWithGlobalDefaultsAreApplied() and
testRenderWithUserOverridesGlobalDefaults() or only one unique test name).
📜 Review details
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (15)
CHANGELOG.mdtests/Form/InputCheckboxTest.phptests/Form/InputHiddenTest.phptests/Form/InputNumberTest.phptests/Form/InputPasswordTest.phptests/Form/InputRadioTest.phptests/Form/InputRangeTest.phptests/Form/InputResetTest.phptests/Form/InputSearchTest.phptests/Form/InputSubmitTest.phptests/Form/InputTelTest.phptests/Form/InputTextTest.phptests/Form/InputTimeTest.phptests/Form/InputUrlTest.phptests/Form/InputWeekTest.php
🧰 Additional context used
🧠 Learnings (7)
📓 Common 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: 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.
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.
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 the ui-awesome/html repository, short variable names (e.g., 2-character names like `$id`) are acceptable in test files and should not be flagged. PHPMD's short-variable rule does not need to be strictly followed in test code.
📚 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/InputRadioTest.phptests/Form/InputTimeTest.phptests/Form/InputSearchTest.phptests/Form/InputTelTest.phptests/Form/InputRangeTest.phptests/Form/InputNumberTest.phptests/Form/InputSubmitTest.phptests/Form/InputResetTest.phptests/Form/InputCheckboxTest.phptests/Form/InputTextTest.phptests/Form/InputUrlTest.phptests/Form/InputPasswordTest.phptests/Form/InputHiddenTest.phptests/Form/InputWeekTest.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/InputRadioTest.phptests/Form/InputTimeTest.phptests/Form/InputSearchTest.phptests/Form/InputTelTest.phptests/Form/InputRangeTest.phptests/Form/InputNumberTest.phptests/Form/InputSubmitTest.phptests/Form/InputResetTest.phptests/Form/InputCheckboxTest.phptests/Form/InputTextTest.phptests/Form/InputUrlTest.phptests/Form/InputPasswordTest.phptests/Form/InputHiddenTest.phptests/Form/InputWeekTest.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/InputSearchTest.phptests/Form/InputCheckboxTest.php
📚 Learning: 2026-02-11T14:58:07.498Z
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 37
File: src/List/Dl.php:74-86
Timestamp: 2026-02-11T14:58:07.498Z
Learning: In the ui-awesome/html repository, short method implementations (like the 3-line `afterRun` method duplicated across `Dl`, `Ol`, and `Ul` classes) should not be extracted into traits. The maintainer prefers to tolerate such duplication rather than create additional abstractions for brief code.
Applied to files:
CHANGELOG.md
📚 Learning: 2026-02-06T21:37:51.711Z
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.
Applied to files:
CHANGELOG.md
📚 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 the ui-awesome/html repository, short variable names (e.g., 2-character names like `$id`) are acceptable in test files and should not be flagged. PHPMD's short-variable rule does not need to be strictly followed in test code.
Applied to files:
CHANGELOG.md
🧬 Code graph analysis (13)
tests/Form/InputRadioTest.php (1)
src/Form/InputRadio.php (1)
InputRadio(41-175)
tests/Form/InputTimeTest.php (1)
src/Form/InputTime.php (1)
InputTime(51-96)
tests/Form/InputTelTest.php (1)
src/Form/InputTel.php (1)
InputTel(46-94)
tests/Form/InputRangeTest.php (1)
src/Form/InputRange.php (1)
InputRange(48-91)
tests/Form/InputNumberTest.php (1)
src/Form/InputNumber.php (1)
InputNumber(44-90)
tests/Form/InputSubmitTest.php (1)
src/Form/InputSubmit.php (1)
InputSubmit(37-80)
tests/Form/InputResetTest.php (1)
src/Form/InputReset.php (1)
InputReset(30-67)
tests/Form/InputCheckboxTest.php (1)
src/Form/InputCheckbox.php (1)
InputCheckbox(41-181)
tests/Form/InputTextTest.php (1)
src/Form/InputText.php (1)
InputText(45-94)
tests/Form/InputUrlTest.php (1)
src/Form/InputUrl.php (1)
InputUrl(46-94)
tests/Form/InputPasswordTest.php (1)
src/Form/InputPassword.php (1)
InputPassword(44-91)
tests/Form/InputHiddenTest.php (1)
src/Form/InputHidden.php (1)
InputHidden(31-68)
tests/Form/InputWeekTest.php (1)
src/Form/InputWeek.php (1)
InputWeek(51-96)
🪛 PHPMD (2.15.0)
tests/Form/InputRadioTest.php
[error] 649-652: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 664-667: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 1112-1118: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)
(StaticAccess)
tests/Form/InputTimeTest.php
[error] 450-453: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 465-468: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
tests/Form/InputSearchTest.php
[error] 462-465: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 477-480: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
tests/Form/InputTelTest.php
[error] 452-455: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 467-470: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
tests/Form/InputRangeTest.php
[error] 450-453: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 465-468: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 742-748: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)
(StaticAccess)
[error] 758-761: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)
(StaticAccess)
tests/Form/InputNumberTest.php
[error] 509-512: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 524-527: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 896-902: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)
(StaticAccess)
tests/Form/InputSubmitTest.php
[error] 505-508: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 520-523: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
tests/Form/InputResetTest.php
[error] 417-420: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 432-435: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
tests/Form/InputCheckboxTest.php
[error] 639-642: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 654-657: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 1102-1108: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)
(StaticAccess)
[error] 1118-1121: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)
(StaticAccess)
tests/Form/InputTextTest.php
[error] 462-465: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 477-480: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
tests/Form/InputUrlTest.php
[error] 452-455: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 467-470: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
tests/Form/InputPasswordTest.php
[error] 461-464: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 476-479: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 782-788: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)
(StaticAccess)
[error] 798-801: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)
(StaticAccess)
tests/Form/InputHiddenTest.php
[error] 438-441: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 453-456: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 649-655: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)
(StaticAccess)
[error] 665-668: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithUserOverridesGlobalDefaults'. (undefined)
(StaticAccess)
tests/Form/InputWeekTest.php
[error] 450-453: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
[error] 465-468: Avoid using static access to class '\UIAwesome\Html\Core\Factory\SimpleFactory' in method 'testRenderWithGlobalDefaultsAreApplied'. (undefined)
(StaticAccess)
🔇 Additional comments (40)
tests/Form/InputHiddenTest.php (3)
438-456: Clearer global-defaults assertion.The exact HTML expectation makes the behavior explicit and consistent with the refactor goal.
620-620: String-cast path verified.Casting to string here cleanly exercises
__toString()without going throughrender().
649-668: User override coverage looks solid.The exact HTML assertion clearly validates that the user
idwins over the global default.tests/Form/InputUrlTest.php (3)
452-470: Exact default rendering assertion looks good.This tightens the test to validate the full output deterministically.
744-744:__toString()coverage is now explicit.Casting to string is a clean way to exercise the magic method directly.
775-781: User overrides test is clearer now.The full HTML equality check makes the override behavior unambiguous.
tests/Form/InputTimeTest.php (3)
450-468: Global defaults assertion is more precise.The heredoc + assertSame approach better validates the rendered output.
735-735: Good use of string-cast for__toString().This makes the intent of the test explicit.
766-772: Override behavior is clearly verified.The exact HTML expectation matches the stricter assertion style.
tests/Form/InputPasswordTest.php (3)
461-479: Precise global-default output check.The heredoc + assertSame makes the expectation explicit and stable.
753-753:__toString()verification is clean.Casting to string keeps the test focused on the magic method.
782-801: Override test matches the new strict style.Full HTML comparison clearly validates user overrides of globals.
tests/Form/InputCheckboxTest.php (2)
639-657: Global defaults test is tighter now.Exact HTML comparison makes the behavior clear and deterministic.
1102-1121: User override assertion looks good.The heredoc expectation confirms the override behavior precisely.
tests/Form/InputTextTest.php (3)
462-480: Exact default rendering assertion is solid.This aligns well with the new strict output checks.
754-754:__toString()path is explicitly tested.The string cast keeps the test intent clear.
785-790: Override expectation is unambiguous.Full HTML equality clearly captures the precedence rule.
tests/Form/InputRadioTest.php (3)
649-667: Global defaults test tightened appropriately.Exact HTML output comparison is clear and stable.
1039-1039: Direct__toString()validation is good.String casting keeps the test minimal and focused.
1112-1126: Override test is explicit and correct.The heredoc assertion clarifies the override behavior.
tests/Form/InputTelTest.php (3)
450-471: LGTM — stricter assertions and proper global-state cleanup.The switch to
assertSame()with exact heredoc HTML, the multi-linesetDefaultsformatting, and the reset to an empty array are all correct and consistent with the broader test suite refactor.
738-747: LGTM —__toString()path now tested via explicit string cast.Using
(string) InputTel::tag()->id(null)directly exercises the__toString()magic method, which is a more accurate test of that code path than callingrender().
771-784: LGTM — user-override test now asserts full rendered output.The exact HTML assertion confirms that
classcomes from global defaults whileidis overridden by the user-provided value, and the cleanup follows correctly.tests/Form/InputRangeTest.php (3)
448-469: LGTM — global defaults test refactored to exact HTML matching.
707-716: LGTM —__toString()tested via string cast.
740-762: LGTM — user-override test with full HTML assertion and cleanup.tests/Form/InputWeekTest.php (3)
448-469: LGTM — exact HTML assertion for global defaults.
729-738: LGTM —__toString()via string cast.
762-775: LGTM — user-override test with strict assertion.tests/Form/InputNumberTest.php (3)
507-528: LGTM — global defaults test with exact HTML matching.
855-864: LGTM —__toString()via string cast.
894-913: LGTM — user-override test with strict output validation.tests/Form/InputSearchTest.php (3)
460-481: LGTM — global defaults test refactored to exact matching.
748-757: LGTM —__toString()via string cast.
781-794: LGTM — user-override test with full HTML assertion.tests/Form/InputResetTest.php (2)
415-436: LGTM — global defaults test with exact HTML assertion.
637-650: LGTM — user-override test refactored to strict matching.tests/Form/InputSubmitTest.php (3)
503-524: LGTM — global defaults test with exact HTML assertion and cleanup.
692-701: LGTM —__toString()via string cast.
725-738: LGTM — user-override test with strict output validation.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
|
@coderabbitai aprove ? |
|
✅ Test improvements: All changes replace partial string matching ( ✅ Consistent formatting: Standardized multi-line array syntax for ✅ Proper string casting: Updated ✅ No production code changes: All modifications are confined to test files, minimizing risk. The refactoring strengthens the test suite by ensuring exact HTML output matches expectations rather than just checking for substrings. 🧠 Learnings used✅ Actions performedComments resolved and changes approved. |
assertSame() for rendering with testRenderWithGlobalDefaultsAreApplied() and testRenderWithGlobalDefaultsAreApplied().assertSame() for rendering with testRenderWithGlobalDefaultsAreApplied() and testRenderWithUserOverridesGlobalDefaults().
Pull Request