WordPress.org

Make WordPress Core

Opened 12 months ago

Last modified 8 days 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:
PR Number:

Description

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 (12)

#1 @desrosj
12 months ago

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

#2 @SergeyBiryukov
12 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
12 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
12 months ago

PHPUnit 8.0 and 8.0.1 have officially been released.

#5 @desrosj
12 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.

https://travis-ci.org/WordPress/wordpress-develop/jobs/490350822

#6 @pento
11 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
8 months ago

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

https://github.com/krakjoe/pcov

Requires phpunit v8. Improves code coverage performance significantly.

#8 @ZanderZ
8 weeks 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
9 days ago

Also interested to hear a status update on this.

#10 @johnbillion
8 days ago

  • Keywords needs-patch added

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

#11 @SergeyBiryukov
8 days 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
8 days 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

Note: See TracTickets for help on using tickets.