Make WordPress Core

Opened 14 months ago

Last modified 6 weeks ago

#46149 assigned task (blessed)

PHPUnit 8.x support

Reported by: SergeyBiryukov Owned by: netweb
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: needs-patch
Focuses: Cc:


Background: #43218

PHPUnit 8.0.0 is scheduled for February 2019. The changelog includes some backwards compatibility breaks.

From the PHPUnit 7 announcement (February 2, 2018):

Looking Forward

The following methods do not have a return value and should therefore have a void return type declaration:

  • PHPUnit\Framework\TestCase::setUpBeforeClass()
  • PHPUnit\Framework\TestCase::setUp()
  • PHPUnit\Framework\TestCase::assertPreConditions()
  • PHPUnit\Framework\TestCase::assertPostConditions()
  • PHPUnit\Framework\TestCase::tearDown()
  • PHPUnit\Framework\TestCase::tearDownAfterClass()
  • PHPUnit\Framework\TestCase::onNotSuccessfulTest()

These methods will have a void return type declaration in PHPUnit 8. Please declare your methods that overwrite the above mentioned methods void now so you are not affected by this backward compatibility break.

This is now implemented in PHPUnit 8, so our method signatures are no longer compatible and cause fatal errors:

Fatal error: Declaration of WP_UnitTestCase_Base::setUpBeforeClass() must be compatible with PHPUnit\Framework\TestCase::setUpBeforeClass(): void in tests/phpunit/includes/abstract-testcase.php on line 1110

We could look into using different signatures for different PHPUnit versions in the same way as in [44701]. However, given the large number of tests extending the ::setUp() and ::tearDown() methods, it's probably easier to address this when we bump the required PHP version to 7.

Change History (13)

#1 @desrosj
14 months ago

  • Milestone changed from Awaiting Review to Future Release
  • Type changed from defect (bug) to task (blessed)

#2 @SergeyBiryukov
14 months ago

We could also look into displaying a friendly message instead of a fatal error. Something like:

Looks like you're using PHPUnit 8.x, WordPress currently is only compatible with PHPUnit 7.x. Please use the latest PHPUnit version from the 7.x branch.

#3 @SergeyBiryukov
14 months ago

In 44723:

Build/Test Tools: Display a message about currently supported PHPUnit branch to avoid fatal errors on later versions.

See #46149.

#4 @desrosj
14 months ago

PHPUnit 8.0 and 8.0.1 have officially been released.

#5 @desrosj
14 months ago

Noticed today that the PHP nightly build is now failing from the changes in #43218. This should be fixed when the needed changes are made for this ticket.


#6 @pento
14 months ago

Nightly switched from PHP 7.4 to PHP 8.0. #46235 is for adding PHP 7.4 back to the test matrix.

#7 @conner_bw
11 months ago

Please consider upgrading. I ran into this issue today trying to setup pcov:


Requires phpunit v8. Improves code coverage performance significantly.

#8 @ZanderZ
4 months ago

In February, PHPUnit 7 support will end and only PHPUnit 8 and 9 (to be released on February 7) will be supported.

The tickets says "it's probably easier to address this when we bump the required PHP version to 7."
Is there any news related to that?

#9 @davidshq
3 months ago

Also interested to hear a status update on this.

#10 @johnbillion
3 months ago

  • Keywords needs-patch added

There isn't one. If someone wants to work on this, that would be great.

#11 follow-up: @SergeyBiryukov
3 months ago

Note that this still depends on bumping the required PHP version to 7.

As of this time, the decision has not been made yet.

#12 @netweb
2 months ago

  • Owner set to netweb
  • Status changed from new to assigned

I've partially implemented this for a client, will work on bringing those changes here

#13 in reply to: ↑ 11 @ZanderZ
6 weeks ago

Replying to SergeyBiryukov:

Note that this still depends on bumping the required PHP version to 7.

As of this time, the decision has not been made yet.

There has been 0 news on this front since the initial announcement. That announcement said "Depending upon feedback and effectiveness, we can follow up by bumping the required PHP version to 7 as early as December 2019." but that timeframe has clearly passed.

Can the WP team please share some news on this?

Note: See TracTickets for help on using tickets.