Skip to content

Commit

Permalink
Fix PHP 8.3 ReflectionProperty::setValue() deprecation warnings (#3…
Browse files Browse the repository at this point in the history
…4314)

In PHP 8.3, calling `ReflectionProperty::setValue()` with a single
argument (rather than passing `null` for the `$object`) is deprecated.
We do this in a few tests, let's fix it in preparation for running PHP
8.3 in CI.
  • Loading branch information
anomiex authored Nov 28, 2023
1 parent fabc62e commit f5858fd
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Fix PHP 8.3 deprecation warnings about calling `ReflectionProperty::setValue()` with a single argument in tests. No change to the project itself.


2 changes: 1 addition & 1 deletion projects/packages/image-cdn/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-image-cdn",
"version": "0.3.1",
"version": "0.3.2-alpha",
"description": "Serve images through Jetpack's powerful CDN",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/image-cdn/#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/image-cdn/src/class-image-cdn.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
final class Image_CDN {

const PACKAGE_VERSION = '0.3.1';
const PACKAGE_VERSION = '0.3.2-alpha';

/**
* Singleton.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ public function tear_down() {
// l337 h4X0Ring required:
$instance = new ReflectionProperty( Image_CDN::class, 'instance' );
$instance->setAccessible( true );
$instance->setValue( null );
$instance->setValue( null, null );

/**
* Reset the `image_sizes` property, as it persists between class instantiations, since it's static.
*/
$instance = new ReflectionProperty( Image_CDN::class, 'image_sizes' );
$instance->setAccessible( true );
$instance->setValue( null );
$instance->setValue( null, null );

self::delete_author();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Fix PHP 8.3 deprecation warnings about calling `ReflectionProperty::setValue()` with a single argument in tests. No change to the project itself.


4 changes: 2 additions & 2 deletions projects/packages/stats/tests/php/test-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public function tear_down() {
$reflected_class = new \ReflectionClass( 'Automattic\Jetpack\Stats\Main' );
$reflected_property = $reflected_class->getProperty( 'instance' );
$reflected_property->setAccessible( true );
$reflected_property = $reflected_property->setValue( null );
$reflected_property = $reflected_property->setValue( null, null );

$reflected_class = new \ReflectionClass( 'Automattic\Jetpack\Stats\XMLRPC_Provider' );
$reflected_property = $reflected_class->getProperty( 'instance' );
$reflected_property->setAccessible( true );
$reflected_property = $reflected_property->setValue( null );
$reflected_property = $reflected_property->setValue( null, null );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/stats/tests/php/test-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function tear_down() {
$reflected_class = new \ReflectionClass( 'Automattic\Jetpack\Stats\Options' );
$reflected_property = $reflected_class->getProperty( 'options' );
$reflected_property->setAccessible( true );
$reflected_property = $reflected_property->setValue( array() );
$reflected_property = $reflected_property->setValue( null, array() );

parent::tear_down();
}
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/stats/tests/php/test-xmlrpc-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function tear_down() {
$reflected_class = new \ReflectionClass( 'Automattic\Jetpack\Stats\XMLRPC_Provider' );
$reflected_property = $reflected_class->getProperty( 'instance' );
$reflected_property->setAccessible( true );
$reflected_property = $reflected_property->setValue( null );
$reflected_property = $reflected_property->setValue( null, null );
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Fix PHP 8.3 deprecation warnings about calling `ReflectionProperty::setValue()` with a single argument in tests. No change to the project itself.


Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ public function test_checksum_with_disabled_sync_modules( $table, $enabled_modul

$prop = $reflection->getProperty( 'initialized_modules' );
$prop->setAccessible( true );
$prop->setValue( null );
$prop->setValue( null, null );

$this->sync_enabled_modules = $enabled_modules;
add_filter( 'jetpack_sync_modules', array( $this, 'sync_modules_filter' ), 100 );
new Table_Checksum( $table );
remove_filter( 'jetpack_sync_modules', array( $this, 'sync_modules_filter' ) );

// Clean-up.
$prop->setValue( null );
$prop->setValue( null, null );
}

/**
Expand Down

0 comments on commit f5858fd

Please sign in to comment.