Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve PHP 8.3 Compatibility #7678

Merged
merged 7 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
11 changes: 7 additions & 4 deletions tests/php/src/Helpers/PrivateAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ private function call_private_static_method( $class, $method_name, $args = [] )
* @throws ReflectionException If the object could not be reflected upon.
*/
private function set_private_property( $object, $property_name, $value ) {
$property = ( new ReflectionClass( $object ) )->getProperty( $property_name );
$reflection_class = new ReflectionClass( $object );
$property = $reflection_class->getProperty( $property_name );
$property->setAccessible( true );

// Note: In PHP 8, `ReflectionProperty::getValue()` now requires that an object be supplied if it's a
// non-static property.
$property->isStatic() ? $property->setValue( $value ) : $property->setValue( $object, $value );
if ( $property->isStatic() ) {
$reflection_class->setStaticPropertyValue( $property_name, $value );
} else {
$property->setValue( $object, $value );
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/php/src/Infrastructure/SimpleInjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static function ( $class ) {
$object = $injector->make( Fixture\DummyInterface::class );

$this->assertInstanceOf( stdClass::class, $object );
$this->assertObjectHasAttribute( 'class_name', $object );
$this->assertObjectHasProperty( 'class_name', $object );
$this->assertEquals( Fixture\DummyInterface::class, $object->class_name );
}

Expand All @@ -148,7 +148,7 @@ static function ( $class ) {
$object = $injector->make( Fixture\DummyInterface::class );

$this->assertInstanceOf( stdClass::class, $object );
$this->assertObjectHasAttribute( 'class_name', $object );
$this->assertObjectHasProperty( 'class_name', $object );
$this->assertEquals( Fixture\DummyClassWithDependency::class, $object->class_name );
}

Expand Down
12 changes: 11 additions & 1 deletion tests/php/validation/test-class-amp-validation-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ public function test_add_admin_bar_menu_items() {
wp_set_current_user( self::factory()->user->create( [ 'role' => 'administrator' ] ) );
$this->assertTrue( current_user_can( 'manage_options' ) );
AMP_Validation_Manager::add_admin_bar_menu_items( $admin_bar );
$this->assertObjectHasAttribute( 'href', $admin_bar->get_node( 'amp-settings' ) );
$this->assertObjectHasProperty( 'href', $admin_bar->get_node( 'amp-settings' ) );
}

/**
Expand Down Expand Up @@ -1438,6 +1438,16 @@ public function test_add_block_source_comments( $content, $expected, $query ) {
// Remove class name injected by gutenberg_render_layout_support_flag().
$rendered_block = preg_replace( '/\s*(?<= class=")?wp-container-\w+\s*/', '', $rendered_block );

// Remove unique layout ID.
$rendered_block = preg_replace( '/\s*(?<= class=")?has-\d+-columns-columns-layout-\d+\s*/', ' has-2-columns', $rendered_block );

// Remove layout class name and ID.
$rendered_block = str_replace(
' is-layout-flow wp-block-quote-is-layout-flow',
'',
$rendered_block
);

$expected = str_replace(
[
'{{post_id}}',
Expand Down
Loading