Skip to content

Commit 65b18f9

Browse files
committed
Tests: Stop passing objects to static methods through Reflection.
PHP 8.6 has deprecated passing an object to `ReflectionMethod::invoke()` and `ReflectionMethodL::invokeArgs()` when the target method is static. This addresses this within two PHPUnit-related files. Props westonruter. Fixes #66457. git-svn-id: https://develop.svn.wordpress.org/trunk@65248 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 658bcc5 commit 65b18f9

2 files changed

Lines changed: 3 additions & 13 deletions

File tree

‎tests/phpunit/tests/admin/plugin-dependencies/base.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ protected function call_method( $method, ...$args ) {
137137
if ( PHP_VERSION_ID < 80100 ) {
138138
self::$reflected_members[ $method ]->setAccessible( true );
139139
}
140-
$value = self::$reflected_members[ $method ]->invokeArgs( self::$instance, $args );
140+
$object = self::$reflected_members[ $method ]->isStatic() ? null : self::$instance;
141+
$value = self::$reflected_members[ $method ]->invokeArgs( $object, $args );
141142
if ( PHP_VERSION_ID < 80100 ) {
142143
self::$reflected_members[ $method ]->setAccessible( false );
143144
}

‎tests/phpunit/tests/theme/wpThemeJson.php‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8515,18 +8515,7 @@ public static function data_custom_css_for_user_caps() {
85158515
* @param string $expected Expected results.
85168516
*/
85178517
public function test_process_blocks_custom_css( $input, $expected ) {
8518-
$theme_json = new WP_Theme_JSON(
8519-
array(
8520-
'version' => WP_Theme_JSON::LATEST_SCHEMA,
8521-
'styles' => array(),
8522-
)
8523-
);
8524-
$reflection = new ReflectionMethod( $theme_json, 'process_blocks_custom_css' );
8525-
if ( PHP_VERSION_ID < 80100 ) {
8526-
$reflection->setAccessible( true );
8527-
}
8528-
8529-
$this->assertSame( $expected, $reflection->invoke( $theme_json, $input['css'], $input['selector'] ) );
8518+
$this->assertSame( $expected, WP_Theme_JSON::process_blocks_custom_css( $input['css'], $input['selector'] ) );
85308519
}
85318520

85328521
/**

0 commit comments

Comments
 (0)