WordPress / WordPress/WordPress-Coding-Standards
[Task] Add dedicated tests for most Helper classes and traits
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.8k
- Forks
- 521
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 1
Description
The "Helper" classes and traits are currently tested via the sniff (integration) tests.
It would be preferable to have dedicated test for the Helper classes and traits though.
In most cases, setting up these tests shouldn't be hard as when no token walking is needed, we can use the PHPUnit native TestCase as the base class, while when token walking is needed, we can use the UtilityMethodTestCase form PHPCSUtils as a base class.
I propose we add these tests as a separate WPCSSniffHelpers test suite to the PHPUnit configuration.
I propose we add these tests in a Helpers subdirectory of the Tests directory off the project root.
If a class would need multiple tests classes, a sub-subdirectory can be created using the Helper class/trait name as the directory name.
We may need to add an autoload-dev directive to the composer.json file specifically for these tests to get things working, as these tests won't run via the PHPCS native test framework.
When adding tests, Helper specific tests which were added to sniff test classes may be removed if they don't have added value anymore, though in most cases, it will be better to just leave them be.
When dedicated tests have been added for a Helper, the @covers tag(s) for that Helper in sniff specific tests classes should be removed.
Action list
Helper classes
-
ArrayWalkingFunctionsHelperis_array_walking_function()andget_callback_parameter(): #2754
-
FormattingFunctionsHelper(#2713) -
UnslashingFunctionsHelperis_unslashing_function: #2715
-
ValidationHelperis_validated: #2731
-
WPGlobalVariablesHelper -
WPHookHelperget_hook_name_param: #2727
Helper traits
-
EscapingFunctionsTrait: #2755 -
IsUnitTestTrait -
MinimumWPVersionTrait -
PrintingFunctionsTraitis_printing_function,get_printing_functions: #2716
-
SanitizingFunctionsTraitis_sanitizing_function(),is_sanitizing_and_unslashing_function(),get_sanitizing_functions()andget_sanitizing_and_unslashing_functions(): #2756
-
WPDBTrait
Low priority Helper classes
The following Helper classes are low(er) priority for adding dedicated tests as the methods in these are likely to move to PHPCSUtils at some point in the future:
-
ConstantsHelperis_use_of_global_constant:#2752
-
ContextHelperis_in_function_call: #2626is_in_type_test: #2721is_in_isset_or_empty: #2725is_in_array_comparison: #2726is_token_namespaced: #2728
-
DeprecationHelper -
ListHelper -
RulesetPropertyHelper -
SnakeCaseHelper -
VariableHelper
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing sniff integration tests and the PHPUnit configuration, then inspect the helper classes and traits listed in the action list. Add dedicated tests under Tests/Helpers, configure the WPCSSniffHelpers suite, and add autoload-dev in composer.json if needed. Done means the unchecked helpers have coverage and obsolete @covers tags are removed where appropriate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100