Skip to content

Tests: Make data providers in tests/phpunit/tests/pluggable/ public and static - #15176

Closed
rejaulalomkhan wants to merge 2 commits into
WordPress:trunkfrom
rejaulalomkhan:tests/66211-static-dp-pluggable-dir
Closed

rejaulalomkhan wants to merge 2 commits into
WordPress:trunkfrom
rejaulalomkhan:tests/66211-static-dp-pluggable-dir

Conversation

@rejaulalomkhan

@rejaulalomkhan rejaulalomkhan commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Description

Makes the data providers in tests/phpunit/tests/pluggable/ public static. PHPUnit 10+ requires static data providers, and none of these use instance state.

  1. wpRand.php: data_wp_rand_should_return_a_non_negative_integer(), data_wp_rand_should_return_zero_when_min_and_max_are_zero()
  2. signatures.php: get_defined_pluggable_functions(). Its direct call in test_all_pluggable_functions_exist() now uses self::. The get_pluggable_function_signatures() helper is not a provider and is left as is.

Testing

vendor/bin/phpunit --group pluggable
vendor/bin/phpunit -c tests/phpunit/multisite.xml --group pluggable
vendor/bin/phpunit --group pluggable --order-by=random --random-order-seed=12345
vendor/bin/phpunit --filter Tests_Pluggable_Signatures
vendor/bin/phpcs tests/phpunit/tests/pluggable/

All pass (324 tests in the group, 66 of them signature tests); PHPCS: no errors.

Trac ticket: https://core.trac.wordpress.org/ticket/66211


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Use of AI Tools

AI assistance: Yes
Tool(s): Google Antigravity (original change), Claude Code (review follow-up)
Model(s): Gemini 2.5 Pro, Claude Opus 5.5
Used for: Converting the providers, adding the missed signatures.php provider and running the tests. I reviewed every line and take responsibility for the change.

…nd static.

Declares data provider methods as \public static\ in \wpRand.php\.

See #66211.
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props rejaulalomkhan, mukesh27, lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@mukeshpanchal27

Copy link
Copy Markdown
Member

Thanks, @rejaulalomkhan! The two changes in wpRand.php look good.

This PR misses one provider in this directory. get_defined_pluggable_functions() in tests/phpunit/tests/pluggable/signatures.php is a @dataProvider but is still non-static. Its body does not use $this, so it can become public static.

One test also calls it directly, at about line 60:

$defined = wp_list_pluck( $this->get_defined_pluggable_functions(), 0 );

This call still works after the change. For consistency, please update it to self::get_defined_pluggable_functions().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See my comment above.

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with @mukeshpanchal27: please include get_defined_pluggable_functions() in tests/phpunit/tests/pluggable/signatures.php in this directory-wide conversion. It is used as a @dataProvider and remains non-static. Make it public static and update its direct call in test_all_pluggable_functions_exist() to self::get_defined_pluggable_functions(). The separate get_pluggable_function_signatures() helper can stay as it is. Please include the existing signature tests in verification. The two wpRand.php conversions look correct.

AI review · gpt-6

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The directory-wide migration claim is inaccurate because signatures.php still has a non-static data provider, so either that provider must be migrated or the PR description narrowed.

1 open issue
What changed in this PR

This PR updates the two wp_rand() data providers to meet PHPUnit’s static-provider requirement without changing their datasets or test assertions.

Changes:

  • Declares both data provider methods in wpRand.php as public static.
  • Leaves the existing test cases and fixtures unchanged.
File Description
tests/​phpunit/​tests/​pluggable/​wpRand.php Makes both data providers static for PHPUnit compatibility.

Review effort: Balanced

* @return array
*/
public function data_wp_rand_should_return_zero_when_min_and_max_are_zero() {
public static function data_wp_rand_should_return_zero_when_min_and_max_are_zero() {
Follow-up to the data provider changes in the pluggable directory.

See #66211.
@rejaulalomkhan

Copy link
Copy Markdown
Member Author

@mukeshpanchal27 @lancewillett get_defined_pluggable_functions() is now public static, and test_all_pluggable_functions_exist() calls it with self:: (545b066). The pluggable group passes on single site and multisite, including the 66 signature tests. I also corrected the description, which wrongly said the other files had no providers.

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The missing signatures provider is now static and its direct caller uses self::. This addresses the earlier request.

Static checks passed. The affected classes passed together in randomized single-site and multisite runs: 408 tests and 1,383 assertions in each mode.

AI review · gpt-6

wporg-sync pushed a commit that referenced this pull request Oct 31, 2026
Convert the remaining providers and fixture callbacks to static methods. Preserve datasets, expectations, and the already-landed provider cleanup.

Developed in: #14970, #15176, #15180

Props rejaulalomkhan, shailu25, mukesh27.
See #66211.


git-svn-id: https://develop.svn.wordpress.org/trunk@65128 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 31, 2026
Convert the remaining providers and fixture callbacks to static methods. Preserve datasets, expectations, and the already-landed provider cleanup.

Developed in: WordPress/wordpress-develop#14970, WordPress/wordpress-develop#15176, WordPress/wordpress-develop#15180

Props rejaulalomkhan, shailu25, mukesh27.
See #66211.

Built from https://develop.svn.wordpress.org/trunk@65128


git-svn-id: http://core.svn.wordpress.org/trunk@64277 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@lancewillett

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants