fix(tests): Update exception test method names for consistency and clarity,#55
fix(tests): Update exception test method names for consistency and clarity,#55terabytesoftw merged 2 commits intomainfrom
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR renames test methods from a "ForSetting" to "WhenSetting" naming pattern across multiple test files for consistency, updates PHPDoc descriptions in source enums to clarify "values" terminology, and refactors test assertions to use enum-backed values instead of hard-coded strings. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 #55 +/- ##
===========================================
Coverage 100.00% 100.00%
Complexity 171 171
===========================================
Files 88 88
Lines 410 410
===========================================
Hits 410 410 ☔ View full report in Codecov by Sentry. |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
tests/Embedded/ImgTest.php (1)
914-926:⚠️ Potential issue | 🟡 MinorInconsistent method name:
WhenInvalidvsWhenSetting.All other new exception tests in this PR (and in this file) follow the
testThrowInvalidArgumentExceptionWhenSetting*pattern, but this method usesWhenInvalid. Consider renaming totestThrowInvalidArgumentExceptionWhenSettingCrossoriginfor consistency with the PR's stated goal.✏️ Proposed rename
- public function testThrowInvalidArgumentExceptionWhenInvalidCrossorigin(): void + public function testThrowInvalidArgumentExceptionWhenSettingCrossorigin(): void🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/Embedded/ImgTest.php` around lines 914 - 926, Rename the test method testThrowInvalidArgumentExceptionWhenInvalidCrossorigin to match the project's naming convention (e.g., testThrowInvalidArgumentExceptionWhenSettingCrossorigin); update the method declaration only, leaving the assertions and call to Img::tag()->crossorigin('invalid-value') intact so the test behavior is unchanged but the name follows the testThrowInvalidArgumentExceptionWhenSetting* pattern used elsewhere.tests/Metadata/MetaTest.php (1)
645-656:⚠️ Potential issue | 🔴 CriticalThe test will fail with a fatal error because the
Attributeenum does not exist in the codebase.The test imports
AttributefromUIAwesome\Html\Attribute\Values, and line 651 referencesAttribute::HTTP_EQUIV->value. However, exhaustive search of the entire repository confirms that:
- No
Attributeenum exists anywhere- No
HttpEquivenum exists anywhere- The
src/Attribute/Values/directory does not exist- The import path is invalid
When the test runs, it will throw a fatal error (
Class "UIAwesome\Html\Attribute\Values\Attribute" not found) rather than reaching theInvalidArgumentExceptionassertion. Both theAttributeenum and theHttpEquivenum must be created before this test can execute.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/Metadata/MetaTest.php` around lines 645 - 656, Create two enums under the namespace UIAwesome\Html\Attribute\Values named Attribute and HttpEquiv so the test can reference Attribute::HTTP_EQUIV->value and HttpEquiv::cases(); ensure Attribute defines a HTTP_EQUIV case (with the expected string value used by Meta::tag()->httpEquiv) and HttpEquiv exposes the set of allowed http-equiv values used by Enum::normalizeArray(HttpEquiv::cases()); implement them as PHP backed-enums (so ->value works) and place them at the import path referenced by the test so the class autoloader can find them.
📜 Review details
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (13)
CHANGELOG.mdsrc/Form/Values/Capture.phpsrc/Form/Values/Colorspace.phpsrc/Metadata/Values/ShadowRootMode.phptests/Embedded/ImgTest.phptests/Form/InputColorTest.phptests/Form/TextAreaTest.phptests/Metadata/BaseTest.phptests/Metadata/LinkTest.phptests/Metadata/MetaTest.phptests/Metadata/ScriptTest.phptests/Metadata/StyleTest.phptests/Metadata/TemplateTest.php
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 51
File: tests/List/UlTest.php:282-283
Timestamp: 2026-02-21T01:17:50.737Z
Learning: In the ui-awesome/html repository, test assertion messages for `testRenderWith*UsingEnum` methods should remain identical to their non-enum counterparts (without "using enum" suffix). The maintainer prefers this because the underlying method behavior doesn't differentiate between enum and string inputs, so the failure messages should reflect that uniformity.
Learnt from: terabytesoftw
Repo: ui-awesome/html PR: 37
File: tests/Form/InputTextTest.php:448-457
Timestamp: 2026-02-11T14:56:26.855Z
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.
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.
📚 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/Metadata/TemplateTest.phptests/Form/TextAreaTest.phptests/Metadata/BaseTest.phptests/Metadata/StyleTest.phptests/Embedded/ImgTest.phptests/Metadata/MetaTest.phptests/Metadata/LinkTest.phptests/Form/InputColorTest.phptests/Metadata/ScriptTest.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/Metadata/TemplateTest.phptests/Form/TextAreaTest.phptests/Metadata/BaseTest.phptests/Metadata/StyleTest.phptests/Embedded/ImgTest.phptests/Metadata/MetaTest.phptests/Metadata/LinkTest.phptests/Form/InputColorTest.phptests/Metadata/ScriptTest.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/Metadata/TemplateTest.phptests/Form/TextAreaTest.phptests/Metadata/BaseTest.phptests/Metadata/StyleTest.phptests/Embedded/ImgTest.phptests/Metadata/MetaTest.phptests/Metadata/LinkTest.phptests/Form/InputColorTest.phptests/Metadata/ScriptTest.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/Metadata/BaseTest.phptests/Metadata/StyleTest.phptests/Embedded/ImgTest.phptests/Metadata/MetaTest.phptests/Metadata/ScriptTest.php
🧬 Code graph analysis (1)
tests/Metadata/StyleTest.php (2)
tests/Metadata/LinkTest.php (1)
testThrowInvalidArgumentExceptionWhenSettingBlocking(849-861)tests/Metadata/ScriptTest.php (1)
testThrowInvalidArgumentExceptionWhenSettingBlocking(1038-1050)
🪛 PHPMD (2.15.0)
tests/Embedded/ImgTest.php
[error] 921-921: Avoid using static access to class '\UIAwesome\Html\Helper\Enum' in method 'testThrowInvalidArgumentExceptionWhenInvalidCrossorigin'. (undefined)
(StaticAccess)
[error] 921-921: Avoid using static access to class '\UIAwesome\Html\Attribute\Values\Crossorigin' in method 'testThrowInvalidArgumentExceptionWhenInvalidCrossorigin'. (undefined)
(StaticAccess)
[error] 935-935: Avoid using static access to class '\UIAwesome\Html\Helper\Enum' in method 'testThrowInvalidArgumentExceptionWhenSettingDecoding'. (undefined)
(StaticAccess)
[error] 935-935: Avoid using static access to class '\UIAwesome\Html\Attribute\Values\Decoding' in method 'testThrowInvalidArgumentExceptionWhenSettingDecoding'. (undefined)
(StaticAccess)
[error] 949-949: Avoid using static access to class '\UIAwesome\Html\Helper\Enum' in method 'testThrowInvalidArgumentExceptionWhenSettingFetchpriority'. (undefined)
(StaticAccess)
[error] 949-949: Avoid using static access to class '\UIAwesome\Html\Attribute\Values\Fetchpriority' in method 'testThrowInvalidArgumentExceptionWhenSettingFetchpriority'. (undefined)
(StaticAccess)
[error] 963-963: Avoid using static access to class '\UIAwesome\Html\Helper\Enum' in method 'testThrowInvalidArgumentExceptionWhenSettingLoading'. (undefined)
(StaticAccess)
[error] 963-963: Avoid using static access to class '\UIAwesome\Html\Attribute\Values\Loading' in method 'testThrowInvalidArgumentExceptionWhenSettingLoading'. (undefined)
(StaticAccess)
[error] 977-977: Avoid using static access to class '\UIAwesome\Html\Helper\Enum' in method 'testThrowInvalidArgumentExceptionWhenSettingReferrerpolicy'. (undefined)
(StaticAccess)
[error] 977-977: Avoid using static access to class '\UIAwesome\Html\Attribute\Values\Referrerpolicy' in method 'testThrowInvalidArgumentExceptionWhenSettingReferrerpolicy'. (undefined)
(StaticAccess)
tests/Metadata/LinkTest.php
[error] 856-856: Avoid using static access to class '\UIAwesome\Html\Helper\Enum' in method 'testThrowInvalidArgumentExceptionWhenSettingBlocking'. (undefined)
(StaticAccess)
[error] 856-856: Avoid using static access to class '\UIAwesome\Html\Attribute\Values\Blocking' in method 'testThrowInvalidArgumentExceptionWhenSettingBlocking'. (undefined)
(StaticAccess)
[error] 870-870: Avoid using static access to class '\UIAwesome\Html\Helper\Enum' in method 'testThrowInvalidArgumentExceptionWhenSettingCrossorigin'. (undefined)
(StaticAccess)
[error] 870-870: Avoid using static access to class '\UIAwesome\Html\Attribute\Values\Crossorigin' in method 'testThrowInvalidArgumentExceptionWhenSettingCrossorigin'. (undefined)
(StaticAccess)
[error] 884-884: Avoid using static access to class '\UIAwesome\Html\Helper\Enum' in method 'testThrowInvalidArgumentExceptionWhenSettingFetchpriority'. (undefined)
(StaticAccess)
[error] 884-884: Avoid using static access to class '\UIAwesome\Html\Attribute\Values\Fetchpriority' in method 'testThrowInvalidArgumentExceptionWhenSettingFetchpriority'. (undefined)
(StaticAccess)
tests/Metadata/ScriptTest.php
[error] 1045-1045: Avoid using static access to class '\UIAwesome\Html\Helper\Enum' in method 'testThrowInvalidArgumentExceptionWhenSettingBlocking'. (undefined)
(StaticAccess)
[error] 1045-1045: Avoid using static access to class '\UIAwesome\Html\Attribute\Values\Blocking' in method 'testThrowInvalidArgumentExceptionWhenSettingBlocking'. (undefined)
(StaticAccess)
[error] 1059-1059: Avoid using static access to class '\UIAwesome\Html\Helper\Enum' in method 'testThrowInvalidArgumentExceptionWhenSettingCrossorigin'. (undefined)
(StaticAccess)
[error] 1059-1059: Avoid using static access to class '\UIAwesome\Html\Attribute\Values\Crossorigin' in method 'testThrowInvalidArgumentExceptionWhenSettingCrossorigin'. (undefined)
(StaticAccess)
[error] 1073-1073: Avoid using static access to class '\UIAwesome\Html\Helper\Enum' in method 'testThrowInvalidArgumentExceptionWhenSettingFetchpriority'. (undefined)
(StaticAccess)
[error] 1073-1073: Avoid using static access to class '\UIAwesome\Html\Attribute\Values\Fetchpriority' in method 'testThrowInvalidArgumentExceptionWhenSettingFetchpriority'. (undefined)
(StaticAccess)
🔇 Additional comments (11)
src/Form/Values/Colorspace.php (1)
8-8: LGTM — consistent docblock wording cleanup.src/Form/Values/Capture.php (1)
8-8: LGTM — consistent docblock wording cleanup.src/Metadata/Values/ShadowRootMode.php (1)
8-8: LGTM — consistent with the docblock wording updates across sibling value enums.CHANGELOG.md (1)
42-42: LGTM — entry is correctly placed and describes the change accurately.tests/Metadata/StyleTest.php (1)
878-890: LGTM — method rename andAttribute::BLOCKING->valueusage are consistent withLinkTestandScriptTest.tests/Metadata/BaseTest.php (1)
594-606: LGTM — method rename andAttribute::TARGET->valueusage are consistent with the pattern adopted inStyleTestand the wider metadata suite.tests/Metadata/TemplateTest.php (1)
882-894: No action needed — literal'shadowrootmode'is correct.The literal string
'shadowrootmode'is intentional. UnlikeStyleTestandBaseTest,TemplateTestdoes not import the generalAttributeenum. Instead, it imports the template-specificShadowRootModeenum, indicating thatshadowrootmodeis not a case in the generalAttributeenum. The bare string is the appropriate choice here.tests/Form/InputColorTest.php (1)
986-998: Verify whetherAttribute::COLORSPACEexists in the codebase.The review identifies an inconsistency pattern:
StyleTestandBaseTestuseAttribute::BLOCKING->valueandAttribute::TARGET->valuein exception messages, whileInputColorTestuses the literal string'colorspace'. The concern is whether anAttribute::COLORSPACEcase exists that should be used instead.Since
colorspaceis an<input type="color">-specific attribute (similar to how domain-specific enums likeColorspace.phpexist insrc/Form/Values/), the literal string usage may be intentional and correct. However, this cannot be confirmed without locating theAttributeenum definition to verify the presence or absence of aCOLORSPACEcase.tests/Form/TextAreaTest.php (1)
1009-1049: LGTM — renames are clean and consistent.All three
testThrowInvalidArgumentExceptionWhenSetting*renames align with the PR's naming convention and no logic is altered.tests/Metadata/LinkTest.php (1)
849-903: LGTM — renames and enum-backed values are applied consistently.All four exception tests follow the
WhenSettingpattern and correctly replace hard-coded attribute-name strings with enum-backed values. Note thatAttribute::BLOCKINGis not visible in the partial snippet; its existence is covered by the verification script raised inMetaTest.php.tests/Metadata/ScriptTest.php (1)
1038-1092: LGTM — renames and enum-backed values are consistent with the rest of the suite.All four methods follow the
WhenSettingconvention and replace hard-coded strings withAttribute::*->valuereferences, matching the pattern inLinkTest.php.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@tests/Embedded/ImgTest.php`:
- Around line 914-926: Rename the test method
testThrowInvalidArgumentExceptionWhenInvalidCrossorigin to match the project's
naming convention (e.g.,
testThrowInvalidArgumentExceptionWhenSettingCrossorigin); update the method
declaration only, leaving the assertions and call to
Img::tag()->crossorigin('invalid-value') intact so the test behavior is
unchanged but the name follows the testThrowInvalidArgumentExceptionWhenSetting*
pattern used elsewhere.
In `@tests/Metadata/MetaTest.php`:
- Around line 645-656: Create two enums under the namespace
UIAwesome\Html\Attribute\Values named Attribute and HttpEquiv so the test can
reference Attribute::HTTP_EQUIV->value and HttpEquiv::cases(); ensure Attribute
defines a HTTP_EQUIV case (with the expected string value used by
Meta::tag()->httpEquiv) and HttpEquiv exposes the set of allowed http-equiv
values used by Enum::normalizeArray(HttpEquiv::cases()); implement them as PHP
backed-enums (so ->value works) and place them at the import path referenced by
the test so the class autoloader can find them.
Pull Request