Skip to content

Commit

Permalink
Normalize updated closure string representation in PHP 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Nov 4, 2024
1 parent b0e101d commit cbe4317
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/php/src/DevTools/CallbackReflectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,15 @@ public function test_get_source( $function, $source_function, $name, $type, $fil
$this->assertEquals( $name, $source['name'] );
$this->assertEquals( $file, $source['file'] );
$this->assertTrue( is_int( $source['line'] ) );
$this->assertEquals( $source_function, $source['function'] );
$this->assertEquals(
$source_function,
// In PHP 8.4, a closure's string representation changes from {closure} to {closure:Test_AMP_Validation_Manager::test_decorate_shortcode_and_filter_source():1831}. So this is normalized here.
preg_replace(
'/{closure:[^}]+}/',
'{closure}',
$source['function']
)
);
/** @var ReflectionFunction $reflection */
$reflection = $source['reflection'];
$this->assertInstanceOf( $reflection_class, $reflection );
Expand Down
7 changes: 7 additions & 0 deletions tests/php/validation/test-class-amp-validation-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2016,6 +2016,13 @@ public function test_decorate_shortcode_and_filter_source() {
]
);

// In PHP 8.4, a closure's string representation changes from {closure} to {closure:Test_AMP_Validation_Manager::test_decorate_shortcode_and_filter_source():1831}. So this is normalized here.
$filtered_content = preg_replace(
'/{closure:[^}]+}/',
'{closure}',
$filtered_content
);

$this->assertEquals(
preg_split( '/(?=<)/', $expected_content ),
preg_split( '/(?=<)/', $filtered_content )
Expand Down

0 comments on commit cbe4317

Please sign in to comment.