Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/files/generate-ci-matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@
);
}

// todo: move to the main matrix once WP latest is compatible with PHP 8.5.
$matrix[] = array(
'name' => 'PHP tests: PHP 8.5 WP trunk',
'script' => 'test-php',
'php' => '8.5',
'wp' => 'trunk',
'timeout' => 20,
'force-package-tests' => true,
);

// Add WooCommerce tests.
$matrix[] = array(
'name' => 'PHP tests: PHP 7.4 WP latest with WooCommerce',
Expand Down
2 changes: 1 addition & 1 deletion .github/versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ PNPM_VERSION=10.4.0

# Other useful version numbers.
MIN_PHP_VERSION=7.2
MAX_PHP_VERSION=8.4
MAX_PHP_VERSION=8.5
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: [ '7.2', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
php-versions: [ '7.2', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
experimental: [ false ]

steps:
Expand Down
6 changes: 3 additions & 3 deletions docs/monorepo.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ All GitHub Actions configuration for the monorepo, including CI, lives in `.gith

## Compatibility

All projects should be compatible with PHP versions WordPress supports. That's currently PHP 7.2 to 8.4.
All projects should be compatible with PHP versions WordPress supports. That's currently PHP 7.2 to 8.5.

## First Time

Expand Down Expand Up @@ -259,15 +259,15 @@ If a project contains PHP tests (typically PHPUnit), it must define `.scripts.te

A MySQL database is available if needed; credentials may be found in `~/.my.cnf`. Note that the host must be specified as `127.0.0.1`, as when passed `localhost` PHP will try to connect via a Unix domain socket which is not available in the Actions environment.

Tests are run with a variety of supported PHP versions from 7.2 to 8.4. If you have tests that only need to be run once, run them when `PHP_VERSION` matches that in `.github/versions.sh`.
Tests are run with a variety of supported PHP versions from 7.2 to 8.5. If you have tests that only need to be run once, run them when `PHP_VERSION` matches that in `.github/versions.sh`.

#### PHP tests for non-plugins

For all project types other than WordPress plugins, the necessary version of PHPUnit and/or any other tools should be pulled in via Composer.

We currently make use of the following packages in testing; it's encouraged to use these rather than introducing other tools that serve the same purpose.

* [yoast/phpunit-polyfills](https://packagist.org/packages/yoast/phpunit-polyfills) supplies polyfills for compatibility with PHPUnit 8.5 to 9.6, to support PHP 7.2 to 8.4.
* [yoast/phpunit-polyfills](https://packagist.org/packages/yoast/phpunit-polyfills) supplies polyfills for compatibility with PHPUnit 8.5 to 12.4, to support PHP 7.2 to 8.5.
* [automattic/phpunit-select-config](https://packagist.org/packages/automattic/phpunit-select-config) allows for selecting a configuration file based on the version of PHPUnit in use, since configs are often not compatible across major versions since PHPUnit 9.
* PHPUnit's built-in mocking is used for class mocks.
* [brain/monkey](https://packagist.org/packages/brain/monkey) is used for mocking functions, and can also provide some functions for minimal WordPress compatibility.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Improve PHP 8.5 compatibility.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
die( $arg );
} else {
// @phan-suppress-current-line UnusedPluginSuppression @phan-suppress-next-line PhanParamTooFewInternal -- Phan bug with PHP 8.4: https://github.com/phan/phan/issues/4888
die();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
exit( $arg );
} else {
// @phan-suppress-current-line UnusedPluginSuppression @phan-suppress-next-line PhanParamTooFewInternal -- Phan bug with PHP 8.4: https://github.com/phan/phan/issues/4888
exit();
}
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/add-php8.5-enable_ci_tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Improve PHP 8.5 compatibility.
17 changes: 9 additions & 8 deletions projects/plugins/jetpack/sal/class.json-api-links.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,11 @@ public function get_external_service_link( $external_service, $path = '' ) {
public function get_closest_version_of_endpoint( $template_path, $path, $request_method = 'GET' ) {
$closest_endpoint_cache_by_version = & $this->closest_endpoint_cache_by_version;

$closest_endpoint_cache = & $closest_endpoint_cache_by_version[ $this->api->version ];
$api_version = $this->api->version ?? '';
$closest_endpoint_cache = & $closest_endpoint_cache_by_version[ $api_version ];
if ( ! $closest_endpoint_cache ) {
$closest_endpoint_cache_by_version[ $this->api->version ] = array();
$closest_endpoint_cache = & $closest_endpoint_cache_by_version[ $this->api->version ];
$closest_endpoint_cache_by_version[ $api_version ] = array();
$closest_endpoint_cache = & $closest_endpoint_cache_by_version[ $api_version ];
}

if ( ! isset( $closest_endpoint_cache[ $template_path ] ) ) {
Expand All @@ -316,10 +317,10 @@ public function get_closest_version_of_endpoint( $template_path, $path, $request
$matches_by_version = & $this->matches_by_version;

// try to match out of saved matches.
if ( ! isset( $matches_by_version[ $this->api->version ] ) ) {
$matches_by_version[ $this->api->version ] = array();
if ( ! isset( $matches_by_version[ $api_version ] ) ) {
$matches_by_version[ $api_version ] = array();
}
foreach ( $matches_by_version[ $this->api->version ] as $match ) {
foreach ( $matches_by_version[ $api_version ] as $match ) {
$regex = $match->regex;
if ( preg_match( "#^$regex\$#", $path ) ) {
$closest_endpoint_cache[ $template_path ][ $request_method ] = $match->version;
Expand Down Expand Up @@ -382,7 +383,7 @@ public function get_closest_version_of_endpoint( $template_path, $path, $request
// If the endpoint version is less than the requested endpoint version, return the max version found.
if ( ! empty( $max_version_found ) ) {
array_push(
$matches_by_version[ $this->api->version ],
$matches_by_version[ $api_version ],
(object) $max_version_found
);
$closest_endpoint_cache[ $template_path ][ $request_method ] = $max_version_found['version'];
Expand Down Expand Up @@ -417,7 +418,7 @@ protected function get_endpoint_path_versions() {
list( $path, $min_version, $max_version ) = unserialize( $key ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize -- Legacy, see serialization at class.json-api.php.

// Grab the last component of the relative path to use as the top-level key.
$last_path_segment = $this->get_last_segment_of_relative_path( $path );
$last_path_segment = $this->get_last_segment_of_relative_path( $path ) ?? '';

$endpoint_path_versions[ $last_path_segment ][] = array(
'path' => $path,
Expand Down
14 changes: 14 additions & 0 deletions projects/plugins/jetpack/tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ function jetpack_full_sync_immediately_off( $modules ) {
// Load trait for WP_UnitTestCase PHPUnit 10 compat.
require_once __DIR__ . '/WP_UnitTestCase_Fix.php';

// Suppress PHP 8.5 deprecation warnings from WordPress core.
// See here: https://core.trac.wordpress.org/ticket/63061
// @todo: Remove this when resolved in WP core.
if ( PHP_VERSION_ID >= 80500 ) {
set_error_handler(
function ( $errno, $errstr, $errfile = '' ) {
return E_DEPRECATED === $errno
&& $errstr === 'Using null as an array offset is deprecated, use an empty string instead'
&& str_ends_with( $errfile, 'wp-includes/theme.php' );
},
E_ALL
);
}

require $test_root . '/includes/bootstrap.php';

// Load the shortcodes module to test properly.
Expand Down
Loading