Opened 4 weeks ago
Last modified 3 days ago
#65819 new task (blessed)
Test tool and unit test improvements for 7.2
| Reported by: | desrosj | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | Build/Test Tools | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
This ticket is for various fixes and improvements in PHPUnit tests that don't have a more specific ticket, as well as general improvements to the GitHub Actions workflows that run automated testing.
Previous releases:
Change History (21)
This ticket was mentioned in PR #11925 on WordPress/wordpress-develop by @johnbillion.
4 weeks ago
#1
- Keywords has-patch has-unit-tests added
This ticket was mentioned in PR #12835 on WordPress/wordpress-develop by @Soean.
3 weeks ago
#2
## Description
remove_filter( $hook_name, $callback, $priority = 10 ) and remove_action( $hook_name, $callback, $priority = 10 ) take three parameters. A number of places in the PHPUnit test suite pass a fourth one, copied over from the matching add_filter()/add_action() call:
add_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 ); $exists = domain_exists( 'foo', 'bar' ); remove_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
The fourth argument is silently ignored by PHP, but it is misleading: it suggests $accepted_args is part of the callback identity used to locate and unhook the callback, which it is not. Only the hook name, the callback and the priority are relevant.
This removes the superfluous argument throughout the test suite. Where the priority was the default 10, the now-redundant priority argument is dropped as well:
remove_filter( 'domain_exists', array( $this, 'domain_exists_cb' ) );
Non-default priorities are kept, since remove_filter() only finds a callback under the exact priority it was registered with:
remove_filter( 'pre_do_shortcode_tag', array( $this, 'filter_pre_do_shortcode_tag_attr' ), 12 );
No occurrences remain in src/, so this is a test-only change with no behavioural difference.
Trac ticket: https://core.trac.wordpress.org/ticket/65819
This ticket was mentioned in PR #13017 on WordPress/wordpress-develop by rootzero00.
3 weeks ago
#3
Replaces six generic assertTrue( is_callable() ) assertions in
tests/phpunit/tests/customize/widgets.php with PHPUnit's dedicated
assertIsCallable() assertion.
This is a test-only cleanup and does not change WordPress runtime behavior.
## Testing
npm run test:php -- --filter Tests_WP_Customize_Widgets::test_get_setting_args --colors=never --do-not-cache-result- PASS: 1 test, 43 assertions
npm run test:php -- --filter Tests_WP_Customize_Widgets --colors=never --do-not-cache-result- PASS: 28 tests, 410 assertions
Current upstream verification also confirmed that the target file has not
changed since the candidate parent and that the six legacy assertions remain
present on current trunk.
## Use of AI Tools
AI assistance: Yes
Tool(s): ChatGPT
Model(s): GPT-5.6 Sol
Used for: Investigation support, contribution workflow and validation
planning, and drafting assistance. The change was reviewed, understood,
signed, and tested by me.
---
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.
@Soean commented on PR #13017:
3 weeks ago
#4
We have the same pattern in Tests_Multisite_WpCacheSwitchToBlogFallback:
@raulsalvat commented on PR #13017:
3 weeks ago
#5
Thanks — I've added those two occurrences in
Tests_Multisite_WpCacheSwitchToBlogFallback as a focused follow-up.
The additional change is limited to that one file (+2/-2), replacing the
two assertTrue( is_callable() ) assertions with assertIsCallable().
Fresh validation passes:
- targeted multisite method: 1 test, 4 assertions
- full multisite class: 25 tests, 136 assertions
- existing Customize class: 28 tests, 410 assertions
- PHP coding standards: PASS
This ticket was mentioned in PR #13036 on WordPress/wordpress-develop by @Soean.
3 weeks ago
#6
## Description
Four independent clean-ups in the test file. Follow-up to [60906].
- Remove the unused
$user_idsfixture. The property and itswpSetUpBeforeClass()method were copied over from thewp_insert_post()tests. Nothing in this class referencesself::$user_ids, so the only effect was creating three users for every test in the class. - Rename
test_wp_delete_post_returns_false_for_invalid_post()totest_wp_delete_post_returns_null_for_already_deleted_post(). The test assertsassertNull(), and that is the correct expectation: for an ID with no matching row,wp_delete_post()returns thenullcoming out of$wpdb->get_row(), whereasfalseis only returned by the$post_id <= 0guard. The old name described the opposite of what the test covers. - Reuse the
$actionsarray in the assertion loop oftest_wp_delete_post_actions(). The same six action names were spelled out a second time inline, so the registration loop and the assertion loop could drift apart. - Fix the
@ticket @63975annotation. The stray@made the tag invalid, so the test was not associated with the ticket.
No assertion was added, removed or changed, and no test behaviour changes.
Trac ticket: https://core.trac.wordpress.org/ticket/65819
@Soean commented on PR #13036:
3 weeks ago
#8
This ticket was mentioned in PR #13052 on WordPress/wordpress-develop by @Soean.
3 weeks ago
#9
Two test cases still used the legacy PHPUnit stub API. This replaces them with the modern shorthands, which are what the rest of the suite already uses.
### Description
tests/phpunit/tests/pomo/pluralForms.php
// Before ->will( $this->returnValue( 1 ) ); // After ->willReturn( 1 );
tests/phpunit/tests/rest-api/rest-server.php
// Before ->with( $this->equalTo( 400 ) ); // After ->with( 400 );
### Why this is safe
willReturn() is a direct shorthand for will( $this->returnValue() ) and has been available since PHPUnit 5.4. The test suite enforces a minimum of PHPUnit 5.7.21 in tests/phpunit/includes/bootstrap.php, so it is safe on every supported version, and the suite already contains 83 willReturn() calls.
with() wraps any non-Constraint argument in an equalTo() constraint itself, so passing 400 directly is identical in behaviour. The suite already has 43 with() calls that pass values directly.
Note on the first change: that line was originally written as willReturn( 1 ) and switched to the long form in [41725] because of the PHPUnit versions supported back then. That constraint no longer applies, so this effectively reverts an obsolete workaround.
Trac ticket: https://core.trac.wordpress.org/ticket/65819
@mukesh27 commented on PR #13052:
3 weeks ago
#11
Committed at https://core.trac.wordpress.org/changeset/63303
@mukesh27 commented on PR #13017:
3 weeks ago
#13
Committed at https://core.trac.wordpress.org/changeset/63311
This ticket was mentioned in PR #13106 on WordPress/wordpress-develop by @desrosj.
3 weeks ago
#14
PHP 8.6 is due out at the end of 2026. Beta 1 was released on August 13th.
This adds a PHP 8.6 job to the PHPUnit testing matrix, but configures jobs using that version to be allowed to fail.
Trac ticket: Core-65819.
## Use of AI Tools
None
@jorbin commented on PR #13106:
2 weeks ago
#15
I'm not sure that we need to be testing with every DB provider for the time being. What would you think of excluding some of the combinations from the matrix?
This ticket was mentioned in PR #13305 on WordPress/wordpress-develop by @Soean.
8 days ago
#16
Tests_Theme::test_get_theme() wraps a native type check in a boolean assertion. PHPUnit has a dedicated assertion for this, which states the intent directly and reports a more useful message when it fails. The comment above it is reworded in the same change, as it referred to the is_array() call that is no longer there.
This is the last remaining convertible occurrence in the test suite.
Follow-up to [62761], [63311].
Trac ticket: https://core.trac.wordpress.org/ticket/65819
@SergeyBiryukov commented on PR #13305:
5 days ago
#18
Thanks for the PR! Merged in r63401.
@desrosj commented on PR #13106:
4 days ago
#19
I've mostly reverted my original changes in favor of creating a new job solely for PHP 8.6. This makes it much easier to manage the number of combinations and the values passed to the various inputs for the reusable workflow without needing to add a bunch of conditional checks.
@desrosj commented on PR #13106:
3 days ago
#20
We could pare it back further if we'd like. I chose to go with one multisite and one single site job on both the latest LTS version of MySQL and MariaDB. It adds 4, but I think that's reasonable to get feedback while running the latest versions of both projects that WordPress currently recommends to users.
@lancewillett commented on PR #13106:
3 days ago
#21
Looks good to land. We can adjust from there.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
This removes some PHPUnit back-compat that's no longer needed.
This leaves PHPUnit 9 as the only version currently in use.
Trac ticket:
https://core.trac.wordpress.org/ticket/65819
https://core.trac.wordpress.org/ticket/64894
## Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Opus 4.7
Used for: Initial investigation and changes, with follow-ups and fixes by me.