Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for PHP 8 Compatibility #121

Closed
getsource opened this issue Jul 1, 2020 · 8 comments
Closed

Update for PHP 8 Compatibility #121

getsource opened this issue Jul 1, 2020 · 8 comments

Comments

@getsource
Copy link
Member

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

@getsource
Copy link
Member Author

getsource commented Oct 27, 2020

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: sebastianbergmann/phpunit#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
Copy link
Member Author

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
Copy link
Contributor

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
Copy link
Member Author

getsource commented Nov 12, 2020

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:

  • Retrieve the version of PHP from the test environment, whether locally/SSH, depending on config
  • Set composer platform to that version of PHP
  • Install PHPUnit with composer
  • PHPUnit gets rsync'd along with the rest of the prepared environment

In test step:

  • Update test.php to use the version of PHPUnit that gets installed with composer

@jrfnl
Copy link
Member

jrfnl commented Nov 12, 2020

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.

@getsource getsource changed the title Test for PHP 8 Compatibility Update for PHP 8 Compatibility Nov 24, 2020
@ottok
Copy link

ottok commented Nov 27, 2020

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

@getsource
Copy link
Member Author

getsource commented Dec 2, 2020

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

  • Detect PHP 5.6-7.0, and use PHPUnit 5 for it, like is currently happening in master, because these versions are not currently supported by Core's composer configuration.
  • If PHP 8 is detected, instead force PHP 7.4 as the version. This is because:
    • PHPUnit will refuse to install for PHP 8, but works when the necessary dependencies are installed via composer.
    • Core tests currently are set not to run on newer versions of PHPUnit that are compatible with PHP 8.
  • Finally, use composer to install the most appropriate PHPUnit version.

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

@getsource
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants