Skip to content

Conversation

@rodrigoprimo
Copy link
Collaborator

Description

This PR is a continuation of #2581.

In preparation for PHPCS 4.0, which changes the tokenization of namespaced names, this PR adds tests with all variants of namespace names (unqualified, partially qualified, fully qualified, and namespace relative) to the following sniffs: WordPress.Utils.I18nTextDomainFixer, WordPress.Security.NonceVerification, WordPress.NamingConventions.ValidHookName, WordPress.NamingConventions.PrefixAllGlobals, WordPress.PHP.NoSilencedErrors, WordPress.WP.CronInterval, and WordPress.WP.DiscouragedConstants.

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

Thanks for setting up this PR @rodrigoprimo !

Similar to previous remarks in other PRs:

  • The NonceVerification sniff is also handling other function calls, like array_key_exists(), is_string() etc to prevent false positives/negatives.
    These also need tests for the variations of namespaced names.
    I suggest you have a good look at the needs_nonce_check() method.
  • ValidHookName: missing tests for the variations of namespaced names for the target functions themselves (do_action() etc).
  • PrefixAllGlobals: I have a feeling (but haven't verified) that test case file 3 needs additional tests for the extends...
  • PrefixAllGlobals: is missing tests for the variations of namespaced names for the hook functions.
  • CronInterval: is missing tests for the variations of namespaced names for first class callables in the $callback parameter.

Other than that:

  • PrefixAllGlobals: I've confirmed that define() in combination with variations of the namespaced names in the string for the constant name is sufficiently covered by tests already (line 311-315 in test case file 1)
  • DiscouragedConstants: verified that the "use of global constant" in all variations of namespaced names is covered sufficiently.

@rodrigoprimo rodrigoprimo force-pushed the more-namespace-tests branch 2 times, most recently from d72fe47 to 521f28c Compare September 24, 2025 10:50
@rodrigoprimo
Copy link
Collaborator Author

Thanks for the review, @jrfnl!

I added new commits, one per sniff. My idea is that those commits are squashed into the corresponding original commit for each sniff. Let me know if you prefer that I do that (either before or after you review this PR again).

The NonceVerification sniff is also handling other function calls, like array_key_exists(), is_string() etc to prevent false positives/negatives.
These also need tests for the variations of namespaced names.

I don't recall exactly why I did not include them initially (if it was a decision not to include or because I'm adding tests to the utility methods that are used in needs_nonce_check() in a PR that I will pull later). That being said, I agree that it makes sense to include those tests here as well, so I added a new commit with those tests.

ValidHookName: missing tests for the variations of namespaced names for the target functions themselves (do_action() etc).
PrefixAllGlobals: I have a feeling (but haven't verified) that test case file 3 needs additional tests for the extends...
PrefixAllGlobals: is missing tests for the variations of namespaced names for the hook functions.

Done

CronInterval: is missing tests for the variations of namespaced names for first class callables in the $callback parameter.

I just added a test in a new commit for a fully qualified call to a global function, which is the only case that the sniff is handling correctly at the moment. For the other cases, I suggest creating an issue to address this separately, as currently the sniff does not handle them correctly. What do you think?

@rodrigoprimo
Copy link
Collaborator Author

@jrfnl, as we discussed during our call earlier today, I added new commits to this PR to ensure that the namespaced tests use different function names when possible and also to ensure that names with different cases are tested for both non-qualified and fully-qualified global function calls.

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

@rodrigoprimo Just posting the CronInterval follow up comments so you can use them.

Will continue the review after these have been addressed.

@rodrigoprimo rodrigoprimo force-pushed the more-namespace-tests branch 2 times, most recently from c41adfb to 0f2d04b Compare November 11, 2025 18:58
Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

Review status so far:
✅ NoSilencedErrors
✅ CronInterval

Rest still to be reviewed.

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

✅ DiscouragedConstants

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

✅ ValidHookName

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

✏️ PrefixAllGlobals

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

✅ PrefixAllGlobals

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

📝 NonceVerification - didn't finish the review as I can't see the code anymore through the comments.

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

Looked the NonceVerification test over one more time

Definitely better, but this is a complex sniff, so we may still be missing some test variations, though I'm not sure that will be problematic for the migration to PHPCS 4.0.

The one thing which may still be good to cover via tests is the handling of a (global) user-defined customNonceVerificationFunctions when namespaced variations of that same function name are encountered. What do you think ?

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

✅ NonceVerification

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

🎉 Thanks for all your work on this @rodrigoprimo !

Would you like to rebase & squash the commits to atomic ones now ?

@jrfnl jrfnl added this to the 3.3.0 milestone Nov 12, 2025
There were already a few tests with namespaced names, so this commit adds only what was missing in the existing tests.
@rodrigoprimo
Copy link
Collaborator Author

Thanks for reviewing this PR, @jrfnl!

Would you like to rebase & squash the commits to atomic ones now ?

Sure, I just did that and force pushed.

@rodrigoprimo rodrigoprimo requested a review from dingo-d November 14, 2025 12:49
@dingo-d dingo-d merged commit c41a317 into WordPress:develop Nov 17, 2025
29 checks passed
@rodrigoprimo rodrigoprimo deleted the more-namespace-tests branch November 18, 2025 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants