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
@lancewillett commented on PR #13827:
8 days ago
#3
Thanks @irozum
PR #13827 landed in https://core.trac.wordpress.org/changeset/64010
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_domainsnetworkOption.php:data_network_id_parameteroption.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_optionsanitizeOption.php:data_sanitize_option,data_sanitize_option_upload_path,data_sanitize_option_permalink_structurethemeMods.php:data_theme_mod_default_value_with_percent_symbolswpDetermineOptionAutoloadValue.php:data_valueswpPrimeOptionCaches.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
@
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
@
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_nonintegersdoAction.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/phpcson 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
@
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.
@lancewillett commented on PR #13967:
4 days ago
#10
PR #13967 landed in https://core.trac.wordpress.org/changeset/64081
@lancewillett commented on PR #13967:
4 days ago
#11
Thanks, Pablo—and congratulations on your first contribution to WordPress Core! 🎉
#12
@
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 functioninstead ofpublic static function. - All of them are already
public, so most need only thestatickeyword 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_callbackadmin/includesPlugin.php:data_submenu_positionblocks/render.php,blocks/wpBlockParser.phpdb/charset.php(5 providers)dependencies/scripts.phpformatting/emoji.php,formatting/wpTexturize.php(3)functions/wpTimezoneOverrideOffset.phpgeneral/feedLinksExtra.phpimage/functions.php(7)interactivity-api/wpInteractivityAPI-wp-bind.php(2)kses.php,media.php,template.php,theme.phppost/getPost.php,post/wpInsertPost.php(4)rest-api/rest-post-meta-fields.php,rest-api/rest-term-meta-fields.php,rest-api/wpRestAbilitiesV1RunController.phpterm/getTermLink.phpuser.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(): Madepublic static.data_invalid_slug_provider(): Madepublic static.
tests/phpunit/tests/abilities-api/wpAbility.php:data_execute_input(): Madepublic static.data_validate_input_top_level_required(): Madepublic static.data_execute_callback(): Madepublic 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!
@lancewillett commented on PR #13956:
3 days ago
#17
PR #13956 landed in https://core.trac.wordpress.org/changeset/64087
@lancewillett commented on PR #13975:
3 days ago
#19
PR #13975 landed in https://core.trac.wordpress.org/changeset/64088
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_imagewpAddGlobalStylesForBlocks.php:data_wp_get_block_name_from_theme_json_pathwpGetGlobalStylesheet.php:data_should_conditionally_include_font_sizes,data_should_not_conditionally_include_font_sizeswpTheme.php:data_is_block_theme,data_get_file_pathwpThemeGetBlockPatterns.php:data_get_block_patternswpThemeHasThemeJson.php:data_theme_has_theme_json_reports_correctlywpThemeJson.php:data_get_property_value_should_return_string_for_invalid_paths_or_null_valuesdata_sanitize_for_block_with_style_variationsdata_sanitize_with_invalid_style_variationdata_get_styles_for_block_with_style_variationsdata_set_spacing_sizesdata_set_spacing_sizes_when_invaliddata_update_separator_declarationsdata_update_button_width_declarationsdata_custom_css_for_user_capsdata_process_blocks_custom_cssdata_get_block_style_variation_selectordata_append_to_selectordata_prepend_to_selector
wpThemeJsonResolver.php:data_has_same_registered_blocks_when_all_blocks_not_cacheddata_has_same_registered_blocks_when_all_blocks_are_cacheddata_get_core_datadata_get_merged_data_returns_origindata_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:
↓ 22
@
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.
#22
in reply to: ↑ 21
@
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.
@lancewillett commented on PR #14003:
2 days ago
#25
PR #14003 landed in https://core.trac.wordpress.org/changeset/64104
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_validationdata_set_cron_array_returns_false_when_not_updateddata_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
@
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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.