WordPress / phpunit-test-runner

GNU General Public License v2.0
67 stars 64 forks source link

Update for PHP 8 Compatibility #121

Closed getsource closed 3 years ago

getsource commented 4 years ago

We should test the test runner for PHP 8 compatibility so that it's ready when core is compatible.

getsource commented 4 years ago

It looks like this is going to require optionally using a different version of PHPUnit.

I haven't got it to work successfully yet, but the code in question is here.

It's currently downloading/installing https://phar.phpunit.de/phpunit-5.7.phar.

PHPUnit's PHP support page: https://phpunit.de/supported-versions.html

PHPUnit 9 does (or will?) support PHP 8: https://github.com/sebastianbergmann/phpunit/issues/4325 I haven't got this to work yet with the phar yet, though -- looks like composer might be necessary, per some core comments.

This might help: https://core.trac.wordpress.org/ticket/51456#comment:5

Edit: More Details

getsource commented 4 years ago

A quick note that prepare.php can be run on a different server and may have different PHP available from where the tests are actually run, so we should be sure that the correct version of PHPUnit gets installed for the destination PHP version.

javiercasares commented 4 years ago

inside functions.php

funtion detect_phpunit_file() {
  if(version_compare(PHP_VERSION, '8.0') >= 0 ) {
    return 'https://phar.phpunit.de/phpunit-9.phar';
  } else {
    return 'https://phar.phpunit.de/phpunit-5.7.phar';
  }
  return 'https://phar.phpunit.de/phpunit-5.7.phar';
}

update the line on prepare

'wget -O ' . escapeshellarg( $WPT_PREPARE_DIR . '/phpunit.phar' ) . ' ' . detect_phpunit_file(),

about the PHP_VERSION, we should try the get_env_details()that returns$env = array( 'php_version' => phpversion(),so change it with $env['php_version']` if we can access that.

getsource commented 4 years ago

I've been sick and not able to get to this, but wanted to be sure to pass on this info, since it should help:

I asked if it's possible to use Composer to install based on a different version of PHP that is not the current one on the system.

From @jrfnl: https://wordpress.slack.com/archives/C02RQBWTW/p1605101934303000?thread_ts=1605072913.278300&cid=C02RQBWTW

Yes, you can use the platform key for that, like so:

"config": {
"platform": {
"php": "5.6.40"
}
},

@jrfnl also noted this, which I think is the best option: You can also set platform from the command-line (or overrule it) if needs be via a script.

This would require composer on the prepare side (I don't believe it is currently required), but that should be fine as long as test reporters are notified ahead of time.

Putting it all together, we can: In prepare step:

In test step:

jrfnl commented 4 years ago

Additional note based on the above discussion:

The WP Core test suite is NOT compatible with PHPUnit 8/9 and will actively block itself from being run with any PHPUnit version > 7.5. A hack has been used to get round the PHPUnit 7 incompatibility with PHP 8 (WP local copy of some of the PHPUnit 9 files which overload the same files from PHPUnit 7), so the test suite will run on PHP 8 using PHPUnit 7.5.20, but ONLY if installed via Composer. The Phar will not work as PHPUnit 7 is no longer supported and the last Phar generated contains dependencies of PHPUnit which are incompatible with PHP 8. If PHPUnit is installed via Composer, the most recent version of those dependencies compatible with PHPUnit 7 will be installed, which will allow the tests to run on PHP 8 with PHPUnit 7.

ottok commented 3 years ago

Forcing phpunit 7.5 to install despite its own ^7.1 restriction was the solution. Works now: image

getsource commented 3 years ago

I chatted with @jrfnl (thank you!!) and together decided these steps would be best to make this compatible with PHP 5.6->8.X:

(@jrfnl If I missed anything, or any of this is off, please do feel free to correct me!)

getsource commented 3 years ago

Fixed by: #132

Here are the currently running and not-currently-reporting hosts, so that we can pay attention if anything breaks:

Active Test Reporters

    A2 Hosting
    Altis by Human Made
    AMIMOTO
    Conetix
    CynderHost
    DreamHost
    InMotion Hosting Test Bot
    Kinsta
    ManagedWPHosting
    Morgan Digital
    redIT
    redIT
    SAKURA internet
    Seravo
    SHIFTER
    SiteGround Bot
    Tuonetti
    Wetopi
    WordPress.org GitHub Actions
    XetNET

Registered, but no reports in >25 Revisions

    Bluehost
    Cloudways
    GoDaddy
    ICDSoft
    IONOS
    Nexcess
    Onyx
    Pantheon
    RAIDBOXES
    Savvii
    Touchstone Bot
    WP-Cloud
    WPMU DEV
    WPWebHost
    XSERVER
    XSERVER
    ZNETLIVE