From 2f9a0a2e8f1d16fa27d25b4093b571b6d5be7f3d Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com> Date: Tue, 3 Nov 2026 11:26:51 -0500 Subject: [PATCH] Build/Test Tools: Avoid passing an object when invoking static methods via Reflection. PHP 8.6 deprecates passing an object to `ReflectionMethod::invoke()` and `ReflectionMethod::invokeArgs()` when the method is static. This updates the `call_method()` helper in the plugin dependencies tests to pass `null` for static methods, and calls the public static `WP_Theme_JSON::process_blocks_custom_css()` method directly instead of through Reflection. Co-Authored-By: Claude Opus 5.5 --- .../tests/admin/plugin-dependencies/base.php | 3 ++- tests/phpunit/tests/theme/wpThemeJson.php | 13 +------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/tests/phpunit/tests/admin/plugin-dependencies/base.php b/tests/phpunit/tests/admin/plugin-dependencies/base.php index bcec6f7da65d8..bcfbc35aa74ef 100644 --- a/tests/phpunit/tests/admin/plugin-dependencies/base.php +++ b/tests/phpunit/tests/admin/plugin-dependencies/base.php @@ -137,7 +137,8 @@ protected function call_method( $method, ...$args ) { if ( PHP_VERSION_ID < 80100 ) { self::$reflected_members[ $method ]->setAccessible( true ); } - $value = self::$reflected_members[ $method ]->invokeArgs( self::$instance, $args ); + $object = self::$reflected_members[ $method ]->isStatic() ? null : self::$instance; + $value = self::$reflected_members[ $method ]->invokeArgs( $object, $args ); if ( PHP_VERSION_ID < 80100 ) { self::$reflected_members[ $method ]->setAccessible( false ); } diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index ae3b9fc08c13c..56c448ee1c43a 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -8515,18 +8515,7 @@ public static function data_custom_css_for_user_caps() { * @param string $expected Expected results. */ public function test_process_blocks_custom_css( $input, $expected ) { - $theme_json = new WP_Theme_JSON( - array( - 'version' => WP_Theme_JSON::LATEST_SCHEMA, - 'styles' => array(), - ) - ); - $reflection = new ReflectionMethod( $theme_json, 'process_blocks_custom_css' ); - if ( PHP_VERSION_ID < 80100 ) { - $reflection->setAccessible( true ); - } - - $this->assertSame( $expected, $reflection->invoke( $theme_json, $input['css'], $input['selector'] ) ); + $this->assertSame( $expected, WP_Theme_JSON::process_blocks_custom_css( $input['css'], $input['selector'] ) ); } /**