Skip to content

Update PHP support to 8.2–8.5 - #440

Open
rahulsprajapati wants to merge 1 commit into
10up:developfrom
rahulsprajapati:php-8.2-8.5-compat
Open

rahulsprajapati wants to merge 1 commit into
10up:developfrom
rahulsprajapati:php-8.2-8.5-compat

Conversation

@rahulsprajapati

Copy link
Copy Markdown
Contributor

Description of the Change

Raises the minimum supported PHP version to 8.2 and tests the plugin on PHP 8.2 through 8.5.

PHP version declarations

  • autoshare-for-twitter.php: the Requires PHP header and the bootstrap guard minimum_php_requirement() now say 8.2. The guard stays, so sites on older PHP still get the admin notice.
  • readme.txt: adds the missing Requires PHP: 8.2 header line.
  • README.md: updates the requirements list.
  • composer.json: config.platform.php is now 8.2. The phpcs:compat script now uses testVersion 8.2-. It was 7.0- before.

CI

  • phpunit.yml and ignore-phpunit.yml: the matrix is now PHP 8.2, 8.3, 8.4 and 8.5. PHP 7.4 and 8.0 are dropped. Both files keep the same matrix, so the required check names still match.
  • phpcs.yml: the PHP pin moves from 7.4 to 8.2.
  • php-compatibility.yml: the PHP pin and testVersion move to 8.2, and the job is now named "PHP minimum 8.2".

Dependencies and lock

  • The lock needed a refresh because its platform-overrides was 7.4. A --lock refresh could not resolve, for two reasons:
    • The lock pinned PHPUnit dev branches that no longer exist upstream, such as phpunit/php-code-coverage 9.2.x-dev.
    • Composer now blocks wp-coding-standards/wpcs 2.x and 10up/phpcs-composer dev-master for security advisories.
  • I changed the dev requirements to 10up/phpcs-composer ^3.0, wp-coding-standards/wpcs ^3.4 and dealerdirect/phpcodesniffer-composer-installer ^1.0, as in Update PHP support to 8.2–8.5 Ad-Refresh-Control#238. WPCS 2 also crashes on PHP 8.1 and later, so the lint job could not run on 8.2 without this change.
  • I ran composer update only for the dev tooling and for composer/ca-bundle. All the lock changes are dev-only, except composer/ca-bundle. That package ships, and it moves to a newer commit inside its current constraint. That fixes its 8 PHP 8.4 "implicitly nullable parameter" deprecations. composer audit now reports no advisories.
  • abraham/twitteroauth is unchanged at 4.0.1. See the follow-up section below.

Lint changes for WPCS 3

  • phpcs.xml already excluded the short-array rule as Generic.Arrays.DisallowShortArraySyntax.Found. WPCS 3 renamed it, so the exclusion now uses Universal.Arrays.DisallowShortArraySyntax.Found, and the project keeps its [] style.
  • I ran phpcbf for the remaining fixable rules, and the changes are style only:
    • It removed use aliases that repeat the class name, such as use ...\Utils as Utils;.
    • It added a space after function in closures.
    • It removed blank lines before closing braces.
    • It removed a leading backslash in one use const.
  • I fixed three things by hand. In includes/rest.php and includes/core.php, use function imports now come before use const imports, as PSR-12 requires. In includes/admin/settings.php, twitter_accounts_field_cb() gets a phpcs:ignore for its unused $args, because the Settings API requires that signature.

No plugin behaviour changes.

Verification

Check PHP version Result
PHPCompatibility 10 (testVersion 8.2-8.5), own code n/a No findings
php -l, own code 8.2, 8.3, 8.4, 8.5 Clean
composer install from the lock, with and without dev 8.2, 8.5 OK
PHPUnit integration suite (bin/install-wp-tests.sh, MariaDB 10.4) 8.2.36, 8.3.37, 8.4.28, 8.5.13 OK, 27 tests, 69 assertions on each
phpcs autoshare-for-twitter.php includes/ (the PHPCS workflow command) 8.2 Clean, exit 0
PHP Compatibility workflow command 8.2 Clean
Runtime check on wp-env with WP_DEBUG_LOG 8.5.13 No notices from the plugin's own code

The runtime check used tests/test-plugin, which mocks the X API, and a seeded test account. It covered these paths:

  • The settings screen, the post list and the post editor.
  • The autoshare/v1/post-autoshare-for-twitter-meta REST route.
  • Publishing through the REST API, including the featured-image upload path, and through WP-CLI.
  • The tenup_autoshare_retweet AJAX handler, the disconnect handler, the front end and cron.

Every request returned 200, or the expected 302, and the plugin's own code logged nothing.

Follow-up for maintainers: abraham/twitteroauth

abraham/twitteroauth is pinned to 4.0.1, which was released in 2022. On PHP 8.4 and 8.5, its HmacSha1 and SignatureMethod classes log 2 "implicitly marking parameter as nullable" deprecations on every request when WP_DEBUG_LOG is on. They also appear in the PHPUnit output. Version 4.0.1 also calls curl_close(), which PHP 8.5 deprecates. These are deprecations, not errors. The plugin works on 8.4 and 8.5.

The fix is a major version upgrade, so I left it out of this PR:

  • 8.x (8.1.1 and later, latest 8.4.0) supports PHP 8.2–8.5 and stops calling curl_close().
  • 9.x drops PHP 8.2 and API v1.1. The plugin uses v1.1 for media/upload, so 9.x does not fit.
  • Moving to 8.x needs a code change. Twitter_API::tweet() passes true as the third argument of post(), and since 7.0 that argument must be an array such as ['jsonPayload' => true].
  • 8.0 also moved the API host to x.com. Testing it needs real X API credentials.

I can open a separate issue for this upgrade if that helps.

Note: the lock still uses minimum-stability: dev without prefer-stable, so several dev packages resolve to branches such as 3.x-dev. I left this as it was.

Closes #436

How to test the Change

No functional changes. Check that the PHPUnit workflow passes on PHP 8.2, 8.3, 8.4 and 8.5, and that the PHPCS and PHP Compatibility workflows pass on PHP 8.2.

To test by hand on PHP 8.5:

  1. Run WP_ENV_PHP_VERSION=8.5 npm run env:start.
  2. Open Settings > Autopost for X/Twitter and confirm that the page loads.
  3. With an X account connected, or with tests/test-plugin active to mock the API, publish a post with autopost turned on. Confirm that the post shows the "Posted to X/Twitter" status.

Changelog Entry

Changed - Bump minimum PHP version from 7.4 to 8.2 and add PHP 8.2, 8.3, 8.4 and 8.5 to CI.

Credits

Props @rahulsprajapati

Checklist:

Raise the minimum PHP to 8.2 and test CI on PHP 8.2 through 8.5.
Move to WPCS 3 so linting runs on PHP 8.2, and refresh the lock.
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

Successfully merging this pull request may close these issues.

Update PHP support to 8.2–8.5

2 participants