Make WordPress Core

Opened 4 months ago

Closed 4 months ago

Last modified 8 weeks ago

#59150 closed defect (bug) (fixed)

Tests: update for PHPUnit Polyfills 1.1.0

Reported by: jrf's profile jrf Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.4 Priority: normal
Severity: normal Version: 6.4
Component: Build/Test Tools Keywords: has-patch has-unit-tests needs-dev-note
Focuses: Cc:

Description

Background

PHPUnit deprecated the assertObjectHasAttribute() and assertObjectNotHasAttribute() methods in PHPUnit 9.6.1, which means that there are currently a number of tests which show deprecation notices in the logs because of this.

By popular request, these methods were brought back, though renamed as assertObjectHasProperty() and assertObjectNotHasProperty() (to prevent confusion with PHP 8.0 attributes), in PHPUnit 10.1.0.

This meant that users which cannot upgrade (yet) to PHPUnit 10.1+ would always have deprecation notices for these methods without recourse.

So, after much discussion, PHPUnit has now backported the new methods to PHPUnit 9.6.11, leaving just the 10.0.x series with a deprecation notice and no recourse.

What does this mean for WordPress ?

WordPress uses the PHPUnit Polyfills to be able to write tests for the "latest" version of PHPUnit (well, almost), with the Polyfills taking care of polyfilling any new PHPUnit methods on older PHPUnit versions.

The PHPUnit Polyfills 1.x series supports PHPUnit 4.x - 9.x.
The PHPUnit Polyfills 2.x series supports PHPUnit 5.x - 10.x.

Due to other, unrelated, feature removals in PHPUnit 10, WordPress is currently still limited to running against PHPUnit 6.x - 9.x with PHPUnit Polyfills 1.x, while the new methods were only included in PHPUnit Polyfills 2.0.0+ (as they were introduced in PHPUnit 10.x).

But... as the assertObjectHasProperty() and assertObjectNotHasProperty() methods have now been backported to PHPUnit 9.x, the PHPUnit Polyfills will now polyfill these methods in the 1.x series as well, which means that by upgrading to the latest PHPUnit Polyfills release - 1.1.0 -, we can get rid of the deprecation notices related to the use of the assertObjectHasAttribute() and assertObjectNotHasAttribute() methods.

Implications

I have a patch ready for this and will pull it to GitHub in a moment.

Amongst other things, the patch updates the minimum supported PHPUnit Polyfills version in the tests/phpunit/includes/bootstrap.php to 1.1.0.

This could have implications for plugins/themes running integration tests with WordPress if they have set their PHPUnit Polyfills dependency to a fixed version or have a too strict version constraint (limiting the PHPUnit Polyfills to the 1.0.x series).

The solution for those plugins/themes is to update their version constraints for the PHPUnit Polyfills to allow for the 1.1.x series.

Change History (10)

This ticket was mentioned in PR #5038 on WordPress/wordpress-develop by @jrf.


4 months ago
#1

  • Keywords has-patch has-unit-tests added

See the Trac ticket for an extensive description

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

#2 @jrf
4 months ago

The build for the patch passes and reduces the number of warnings on PHPUnit 9.x from 80+ to 60.

This ticket was mentioned in Slack in #core-test by jrf. View the logs.


4 months ago

#4 @ayeshrajans
4 months ago

This could have implications for plugins/themes running integration tests with WordPress if they have set their PHPUnit Polyfills dependency to a fixed version or have a too strict version constraint (limiting the PHPUnit Polyfills to the 1.0.x series).

I checked the dependents reported on Packagist and found a bunch of automattic plugins that pinned to yoast/phpunit-polyfills v1.0.4. They might need manual updates to resolve the conflicts.

Other than than, none of the tag=wordpress plugin packages with > 100K installs have a strict (~1.0.4) or pinned dependency on yoast/phpunit-polyfills.

#5 @SergeyBiryukov
4 months ago

  • Milestone changed from Awaiting Review to 6.4
  • Owner set to SergeyBiryukov
  • Status changed from new to accepted

#6 @SergeyBiryukov
4 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 56421:

Build/Test Tools: Update PHPUnit Polyfills to version 1.1.0.

PHPUnit 9.6.1 deprecated the assertObjectHasAttribute() and assertObjectNotHasAttribute() methods, leading to deprecation notices in a number of tests.

PHPUnit 10.1.0 brought the methods back by popular request, though renamed as assertObjectHasProperty() and assertObjectNotHasProperty(), to prevent confusion with PHP 8.0 attributes.

This meant that users which cannot (yet) upgrade to PHPUnit 10.1+ would always have deprecation notices for these methods without recourse. So, after much discussion, the new methods have been backported to PHPUnit 9.6.11, leaving just the 10.0.x series with a deprecation notice and no recourse.

What does this mean for WordPress?

WordPress uses the PHPUnit Polyfills to be able to write tests for the most recent versions of PHPUnit, with the Polyfills taking care of polyfilling any new PHPUnit methods on older PHPUnit versions.

  • The PHPUnit Polyfills 1.x series supports PHPUnit 4.x to 9.x.
  • The PHPUnit Polyfills 2.x series supports PHPUnit 5.x to 10.x.

WordPress currently runs against PHPUnit 6.x to 9.x with PHPUnit Polyfills 1.x, while the new methods were previously only included in PHPUnit Polyfills 2.0.0+, as they were introduced in PHPUnit 10.x.

Since the assertObjectHasProperty() and assertObjectNotHasProperty() methods have been backported to PHPUnit 9.x, the PHPUnit Polyfills will now include these methods in the 1.x series as well.

By upgrading to the latest PHPUnit Polyfills 1.1.0 release, we can get rid of the deprecation notices related to the use of the assertObjectHasAttribute() and assertObjectNotHasAttribute() methods.

This could have implications for plugins or themes running integration tests with WordPress if they have set their PHPUnit Polyfills dependency to a fixed version or have a too strict version constraint (limiting the PHPUnit Polyfills to the 1.0.x series). The solution for those plugins or themes is to update their version constraints for the PHPUnit Polyfills to allow for the 1.1.x series.

Follow-up to [51559], [51598].

Props jrf, ayeshrajans.
Fixes #59150.

@SergeyBiryukov commented on PR #5038:


4 months ago
#7

Thanks for the PR! Merged in r56421.

#8 @jrf
4 months ago

  • Keywords needs-dev-note added

Thanks @SergeyBiryukov ! I've added the needs-dev-note keyword for the plugin/theme test implications.

#9 follow-up: @webcommsat
8 weeks ago

Hello @jrf I am following up on this ticket for dev notes. Is there a draft dev note of this change please which I can add to the documentation tracker? Thank you.

From reading the ticket, I understand this could have implications for plugins/ Themes running integration tests with WordPress, and in some cases a manual update will be necessary. Is this something that Marcomms need to include in the email to plugin developers which is currently being drafted? Copying in @meher who is one of the Marcomms team working on this for awareness. From a discussion on email to theme devs I am unsure if that is being wrangled somewhere, and if so, this ticket may be relevant for that too.

Thanks to you and everyone who have been working on this change.

#10 in reply to: ↑ 9 @jrf
8 weeks ago

Replying to webcommsat:

Hello @jrf I am following up on this ticket for dev notes. Is there a draft dev note of this change please which I can add to the documentation tracker? Thank you.

There is no draft dev-note and to be honest, I'm not sure this needs a separate dev-note. In my opinion, it should be mentioned in the "Miscellaneous developer facing changes" dev-note and that should probably be enough.

From reading the ticket, I understand this could have implications for plugins/ Themes running integration tests with WordPress, and in some cases a manual update will be necessary. Is this something that Marcomms need to include in the email to plugin developers which is currently being drafted?

I think it would be a good change to mention in the mail to plugin devs, but it shouldn't need more than just a simple mention "PHPUnit Polyfills 1.1.0 is required for running integration tests with WP 6.4".

I mean if people don't know the Polyfills, it isn't relevant for them as they won't have tests which they run in the context of WP and if they do know the Polyfills, the above suggested mention will be enough for them to know what to do.

Note: See TracTickets for help on using tickets.