Make WordPress Core

Opened 8 days ago

Last modified 5 hours ago

#66211 accepted task (blessed)

Tests: Make PHPUnit data providers public and static

Reported by: lancewillett Owned by: lancewillett
Priority: normal Milestone: 7.2
Component: Build/Test Tools Version:
Severity: normal Keywords: good-first-bug has-patch has-unit-tests
Cc: Focuses: tests

Description

Split from #62004.

PHPUnit 10 deprecated data providers that are not public and static, and PHPUnit 11 removed support for them. On trunk, about 960 of 1,140 data provider methods are not static, across the 512 files that use @dataProvider.

Most need only the static keyword. A provider that uses $this needs a small rework. PHPUnit 9 accepts static providers, so this can land now.

To keep reviews small, please send one PR per directory, and comment here with the directory you're taking.

Change History (28)

This ticket was mentioned in ​PR #13827 on ​WordPress/wordpress-develop by ​@irozum.


8 days ago
#1

  • Keywords has-patch has-unit-tests added; needs-patch removed

Makes the five PHPUnit data provider methods in tests/phpunit/tests/meta/ (isProtectedMeta.php, registerMeta.php) public static, per the migration described in the parent ticket #62004. PHPUnit 10 deprecated non-static data providers and PHPUnit 11 removed support for them entirely; PHPUnit 9 (used here) accepts static providers, so this can land ahead of the PHPUnit upgrade. None of the five providers reference $this, so this is a mechanical signature change with no behavior change — confirmed by running both affected test classes (Tests_Meta_isProtectedMeta, Tests_Meta_Register_Meta), both still fully green.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5
Used for: Implementation and PR description. Reviewed by irozum.

#2 @lancewillett
8 days ago

In 64010:

Tests: Make meta test data providers static.

Declare the five data providers in the meta tests static to prepare for newer PHPUnit versions. The providers do not depend on instance state, and their test data and assertions remain unchanged.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13827

Props irozum.
See #66211.

This ticket was mentioned in ​PR #13956 on ​WordPress/wordpress-develop by ​@therssoftware.


4 days ago
#4

Makes the 14 PHPUnit data provider methods in tests/phpunit/tests/option/ public static, as part of the PHPUnit 10+ migration (#62004). PHPUnit 10 deprecated non-static data providers and PHPUnit 11 removed support for them. PHPUnit 9 accepts static providers, so this can land now.

None of the providers use $this or the factory, so only the method signatures change. Behavior stays the same.

Files changed:

  • multisite.php: data_illegal_names, data_email_domains
  • networkOption.php: data_network_id_parameter
  • option.php: data_bad_option_names, data_valid_but_undesired_option_names, data_option_autoloading, data_option_autoloading_large_option, data_get_option_does_not_hit_the_external_cache_multiple_times_for_the_same_option
  • sanitizeOption.php: data_sanitize_option, data_sanitize_option_upload_path, data_sanitize_option_permalink_structure
  • themeMods.php: data_theme_mod_default_value_with_percent_symbols
  • wpDetermineOptionAutoloadValue.php: data_values
  • wpPrimeOptionCaches.php: data_option_types

Testing:

  • vendor/bin/phpcs tests/phpunit/tests/option/: no issues.
  • Ran each affected test class on both single site and multisite (-c tests/phpunit/multisite.xml). Everything passed.

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

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Used for: Finding and updating the provider signatures, and running the tests. Reviewed by robelsust.

#5 @therssoftware
4 days ago

I'm taking tests/phpunit/tests/option/. PR: ​https://github.com/WordPress/wordpress-develop/pull/13956

All 14 data providers in this directory are now public static. None of them used $this, so only the method signatures change. PHPCS is clean, and the affected test classes pass on both single site and multisite.

#6 @pablodiloreto
4 days ago

I'm taking tests/phpunit/tests/hooks/. It has four data providers (two in doAction.php and two in applyFilters.php), and none of them use $this. I'll link the PR here.

This ticket was mentioned in ​PR #13967 on ​WordPress/wordpress-develop by ​@pablodiloreto.


4 days ago
#7

Makes the four PHPUnit data providers in tests/phpunit/tests/hooks/ public static, as part of the PHPUnit 10+ migration (#62004). None of them use $this, so only the method signatures change.

Files changed:

  • applyFilters.php: data_priority_callback_order_with_integers, data_priority_callback_order_with_unhappy_path_nonintegers
  • doAction.php: data_priority_callback_order_with_integers, data_priority_callback_order_with_unhappy_path_nonintegers

Testing:

  • vendor/bin/phpunit --group hooks, single site and multisite: 168 tests, 450 assertions, same result before and after the change.
  • The 8 warnings in that run are already on trunk: the "float" data sets use expectDeprecation(), which PHPUnit 9 flags as going away in PHPUnit 10. This PR doesn't change them.
  • vendor/bin/phpcs on both files: no issues.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Picking the directory, making the change, running the tests, and drafting this description. I reviewed the diff and the test output.

Opened from the WordPress Contributor Toolkit.

#8 @pablodiloreto
4 days ago

PR: ​https://github.com/WordPress/wordpress-develop/pull/13967

The four providers are now public static. The hooks group passes on single site and multisite, with the same results as before the change.

#9 @lancewillett
4 days ago

In 64081:

Tests: Make hook test data providers static.

Declare the four data providers in the WP_Hook::apply_filters() and WP_Hook::do_action() tests as public static for compatibility with newer PHPUnit versions. The providers return literal data and do not require instance state.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13967

Props pablodiloreto.
See #66211.

​@lancewillett commented on ​PR #13967:


4 days ago
#11

Thanks, Pablo—and congratulations on your first contribution to WordPress Core! 🎉

#12 @mukesh27
4 days ago

I scanned tests/phpunit for every method referenced by a @dataProvider annotation or #[DataProvider] attribute and checked how each one is declared.

Findings

  • 1,005 data providers in 439 files are declared public function instead of public static function.
  • All of them are already public, so most need only the static keyword added.
  • 42 of them reference $this, so they need a small refactor first (e.g. self::, static fixtures, or moving the setup into the test method).
  • Around 220 providers are already public static.

Breakdown by area (top 12)

Area Count Area Count
formatting 103 multisite 34
rest-api 101 post 32
functions 80 theme 28
admin 57 dependencies 26
block-supports 42 media.php 23
kses.php 22 term 20

The remaining ~80 directories/files each have between 1 and 19.

Providers that use $this

  • abilities-api/wpAbility.php: data_execute_callback
  • admin/includesPlugin.php: data_submenu_position
  • blocks/render.php, blocks/wpBlockParser.php
  • db/charset.php (5 providers)
  • dependencies/scripts.php
  • formatting/emoji.php, formatting/wpTexturize.php (3)
  • functions/wpTimezoneOverrideOffset.php
  • general/feedLinksExtra.php
  • image/functions.php (7)
  • interactivity-api/wpInteractivityAPI-wp-bind.php (2)
  • kses.php, media.php, template.php, theme.php
  • post/getPost.php, post/wpInsertPost.php (4)
  • rest-api/rest-post-meta-fields.php, rest-api/rest-term-meta-fields.php, rest-api/wpRestAbilitiesV1RunController.php
  • term/getTermLink.php
  • user.php, user/capabilities.php (3)

Proposed approach

To keep the changes easy to review, I'd suggest one PR per test area (e.g. formatting, rest-api, functions, ...). Each PR would add static to the providers that only need the keyword, and the providers that use $this would be handled in separate, focused PRs.

Moving this to 7.2 make sense.

This ticket was mentioned in ​PR #13975 on ​WordPress/wordpress-develop by ​@huzaifaalmesbah.


3 days ago
#13

Description

Makes the PHPUnit data provider methods in tests/phpunit/tests/abilities-api/ public static, as part of the PHPUnit 10+ migration (#62004).

PHPUnit 10 deprecated non-static data providers and PHPUnit 11 removed support for them. PHPUnit 9 accepts static providers, so this can land now.

Files changed:

  • tests/phpunit/tests/abilities-api/wpAbilityCategoryRegistry.php:
    • data_valid_slug_provider(): Made public static.
    • data_invalid_slug_provider(): Made public static.
  • tests/phpunit/tests/abilities-api/wpAbility.php:
    • data_execute_input(): Made public static.
    • data_validate_input_top_level_required(): Made public static.
    • data_execute_callback(): Made public static. The 'object method' test case now uses an anonymous class instance with the callback method instead of $this.

Note: wpAbilitiesRegistry.php's data provider (data_invalid_category_types) is already declared public static.

Testing Instructions

# Single site suite
npm run test:php -- --test-suffix .php tests/phpunit/tests/abilities-api/

# Multisite suite
npm run test:php -- -c tests/phpunit/multisite.xml --test-suffix .php tests/phpunit/tests/abilities-api/

# Code style check
composer run lint tests/phpunit/tests/abilities-api/wpAbility.php tests/phpunit/tests/abilities-api/wpAbilityCategoryRegistry.php

Expected result: 226 tests, 538 assertions (OK, 100% pass), 0 lint errors.

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Updating data provider signatures and testing. Implementation and test verification were reviewed and executed locally.

​@mukesh27 commented on ​PR #13975:


3 days ago
#14

@huzaifaalmesbah Thanks for the PR!

Since the ticket is marked good-first-bug, it's intended for new contributors. As you're an experienced contributor, please avoid picking up good-first-bug tickets in the future so we can use them to help onboard and support new contributors.

Thanks for understanding!

​@huzaifaalmesbah commented on ​PR #13975:


3 days ago
#15

Sorry about that, Mukesh. I mainly picked this up to show a few new contributors the PR process. I’ll keep this in mind going forward. Thanks!

#16 @lancewillett
3 days ago

In 64087:

Tests: Make option test data providers static.

Declare the 14 data providers in the option tests as public static for compatibility with newer PHPUnit versions. Preserve all datasets and assertions.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13956

Props therssoftware, mukesh27.
See #66211.

#18 @lancewillett
3 days ago

In 64088:

Tests: Make Abilities API test data providers static.

Declare five data providers as public static for compatibility with newer PHPUnit versions. Use an anonymous object for the instance-method callback dataset so it no longer depends on $this, preserving coverage of object-method callables.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13975

Props huzaifaalmesbah.
See #66211.

This ticket was mentioned in ​PR #14003 on ​WordPress/wordpress-develop by ​@therssoftware.


3 days ago
#20

Makes the 28 PHPUnit data provider methods in tests/phpunit/tests/theme/ public static, as part of the PHPUnit 10+ migration (#62004). PHPUnit 10 deprecated non-static data providers and PHPUnit 11 removed support for them. PHPUnit 9 accepts static providers, so this can land now.

None of the providers use $this or the factory, so only the method signatures change. Behavior stays the same.

Files changed:

  • customHeader.php: data_filter_header_image
  • wpAddGlobalStylesForBlocks.php: data_wp_get_block_name_from_theme_json_path
  • wpGetGlobalStylesheet.php: data_should_conditionally_include_font_sizes, data_should_not_conditionally_include_font_sizes
  • wpTheme.php: data_is_block_theme, data_get_file_path
  • wpThemeGetBlockPatterns.php: data_get_block_patterns
  • wpThemeHasThemeJson.php: data_theme_has_theme_json_reports_correctly
  • wpThemeJson.php:
    • data_get_property_value_should_return_string_for_invalid_paths_or_null_values
    • data_sanitize_for_block_with_style_variations
    • data_sanitize_with_invalid_style_variation
    • data_get_styles_for_block_with_style_variations
    • data_set_spacing_sizes
    • data_set_spacing_sizes_when_invalid
    • data_update_separator_declarations
    • data_update_button_width_declarations
    • data_custom_css_for_user_caps
    • data_process_blocks_custom_css
    • data_get_block_style_variation_selector
    • data_append_to_selector
    • data_prepend_to_selector
  • wpThemeJsonResolver.php:
    • data_has_same_registered_blocks_when_all_blocks_not_cached
    • data_has_same_registered_blocks_when_all_blocks_are_cached
    • data_get_core_data
    • data_get_merged_data_returns_origin
    • data_get_style_variations
  • wpThemeJsonSelectorList.php: data_split_selector_list, data_prepend_to_selector_uses_safe_splitting

Testing:

  • vendor/bin/phpcs tests/phpunit/tests/theme/: passed with 0 errors and 0 warnings across all 11 files.
  • Ran all affected test classes on both single site and multisite (-c tests/phpunit/multisite.xml). Everything passed cleanly (399 tests across single site / multisite runs).

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

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Identifying data provider signatures, updating method declarations to public static, and verifying tests across single site and multisite configurations. Implementation and test verification were reviewed and executed locally by robelsust.

#21 follow-up: @therssoftware
3 days ago

I'm taking tests/phpunit/tests/theme/. PR: ​https://github.com/WordPress/wordpress-develop/pull/14003

All 28 data providers across the 9 files in this directory are now public static. None of them used $this, so only the method signatures change. PHPCS is clean (0 errors/warnings), and all affected test classes pass on both single site and multisite configurations.

Last edited 3 days ago by therssoftware (previous) (diff)

#22 in reply to: ↑ 21 @mukesh27
3 days ago

Replying to therssoftware:

I'm taking tests/phpunit/tests/theme/. PR: ​https://github.com/WordPress/wordpress-develop/pull/XXXXX

Feel like AI draft this reply. Make sure to add the proper PR link.

​@mukesh27 commented on ​PR #14003:


3 days ago
#23

@lancewillett This one is ready for commit.

#24 @lancewillett
2 days ago

In 64104:

Tests: Make theme test data providers static.

Declare 28 data providers in the theme tests as public static for compatibility with newer PHPUnit versions. Preserve all datasets and assertions.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14003

Props therssoftware, mukesh27.
See #66211.

This ticket was mentioned in ​PR #14028 on ​WordPress/wordpress-develop by ​@therssoftware.


40 hours ago
#26

Makes the 5 PHPUnit data provider methods in tests/phpunit/tests/cron/ and tests/phpunit/tests/cron.php public static, as part of the PHPUnit 10+ migration (#62004). PHPUnit 10 deprecated non-static data providers and PHPUnit 11 removed support for them. PHPUnit 9 accepts static providers, so this can land now.

None of the providers use $this or the factory, so only the method signatures change. Behavior stays the same.

Files changed:

  • tests/phpunit/tests/cron.php:
    • data_wp_reschedule_event_works_with_args
  • tests/phpunit/tests/cron/getCronArray.php:
    • data_get_cron_array_output_validation
  • tests/phpunit/tests/cron/setCronArray.php:
    • data_set_cron_array_input_validation
    • data_set_cron_array_returns_false_when_not_updated
    • data_set_cron_array_returns_WP_Error_when_not_updated

Testing:

  • vendor/bin/phpcs: passed with 0 errors and 0 warnings across all 3 files.
  • Ran all affected test classes on both single site and multisite (-c tests/phpunit/multisite.xml). Everything passed cleanly (52 tests, 193 assertions across both runs).

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

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Identifying data provider signatures in the cron tests, updating method declarations to public static, and verifying tests across single site and multisite configurations. Implementation and test verification were reviewed and executed locally by robelsust.

#27 @therssoftware
40 hours ago

I'm taking tests/phpunit/tests/cron/ and tests/phpunit/tests/cron.php. PR: ​https://github.com/WordPress/wordpress-develop/pull/14028

All 5 data providers across the 3 cron test files are now public static. None of them used $this, so only the method signatures change. PHPCS is clean (0 errors/warnings), and all affected test classes pass on both single site and multisite configurations.

#28 @lancewillett
5 hours ago

  • Milestone Future Release → 7.2
  • Owner set to lancewillett
  • Status new → accepted
Note: See TracTickets for help on using tickets.