Skip to content

Commit

Permalink
Merge pull request #7678 from ampproject/add/php83
Browse files Browse the repository at this point in the history
Improve PHP 8.3 Compatibility
  • Loading branch information
westonruter committed Nov 28, 2023
2 parents fe560af + f138b04 commit 4f16c6b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
9 changes: 8 additions & 1 deletion .github/actions/setup-node-npm/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ runs:
using: 'composite'
steps:
- name: Configure Node.js cache
uses: actions/cache@v3.3.1
uses: actions/cache@v3.3.2
id: node-npm-cache
env:
SEGMENT_DOWNLOAD_TIMEOUT_MINS: '5'
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('package*.json') }}-${{ hashFiles('.github/actions/setup-node-npm/action.yml') }}

# Since it gets downloaded with npm install, we need to cache it instantly.
- name: Setup puppeteer cache
uses: actions/cache@v3.3.2
with:
path: ~/.cache/puppeteer
key: ${{ runner.os }}-puppeteer

- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/build-test-measure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,6 @@ jobs:
path: ~/.jest-cache
key: ${{ runner.os }}-jest-e2e-${{ matrix.part }}

- name: Setup puppeteer cache
uses: actions/cache@v3.3.2
with:
path: ~/.cache/puppeteer
key: ${{ runner.os }}-puppeteer

- name: Start Docker environment
run: npm run env:start:ci
env:
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/utils/amp-settings-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export async function cleanUpValidatedUrls() {

await page.click('#doaction');
await page.waitForXPath(
'//*[contains(@class, "updated notice")]/p[contains(text(), "forgotten")]'
'//*[contains(@class, "notice") and contains(@class, "updated")]/p[contains(text(), "forgotten")]'
);
await switchUserToTest();
}
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

0 comments on commit 4f16c6b

Please sign in to comment.