WordPress / WordPress/WordPress-Coding-Standards

[Task] Add dedicated tests for most Helper classes and traits

Open
#2,272 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Status: Good first issue Type: Chores/Cleanup
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
  • ArrayWalkingFunctionsHelper
    • is_array_walking_function() and get_callback_parameter(): #2754
  • FormattingFunctionsHelper (#2713)
  • UnslashingFunctionsHelper
    • is_unslashing_function: #2715
  • ValidationHelper
    • is_validated: #2731
  • WPGlobalVariablesHelper
  • WPHookHelper
    • get_hook_name_param: #2727
Helper traits
  • EscapingFunctionsTrait: #2755
  • IsUnitTestTrait
  • MinimumWPVersionTrait
  • PrintingFunctionsTrait
    • is_printing_function, get_printing_functions: #2716
  • SanitizingFunctionsTrait
    • is_sanitizing_function(), is_sanitizing_and_unslashing_function(), get_sanitizing_functions() and get_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:

  • ConstantsHelper
    • is_use_of_global_constant: #2752
  • ContextHelper
    • is_in_function_call: #2626
    • is_in_type_test: #2721
    • is_in_isset_or_empty: #2725
    • is_in_array_comparison: #2726
    • is_token_namespaced: #2728
  • DeprecationHelper
  • ListHelper
  • RulesetPropertyHelper
  • SnakeCaseHelper
  • VariableHelper

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.