From cbe43175ad5981f26806cc560d080918016ba876 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 4 Nov 2024 09:46:00 -0800 Subject: [PATCH] Normalize updated closure string representation in PHP 8.4 --- tests/php/src/DevTools/CallbackReflectionTest.php | 10 +++++++++- .../validation/test-class-amp-validation-manager.php | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/php/src/DevTools/CallbackReflectionTest.php b/tests/php/src/DevTools/CallbackReflectionTest.php index c88ab786af8..edfa2d3480c 100644 --- a/tests/php/src/DevTools/CallbackReflectionTest.php +++ b/tests/php/src/DevTools/CallbackReflectionTest.php @@ -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 ); diff --git a/tests/php/validation/test-class-amp-validation-manager.php b/tests/php/validation/test-class-amp-validation-manager.php index 3779ca29d3c..8b64e9f55e7 100644 --- a/tests/php/validation/test-class-amp-validation-manager.php +++ b/tests/php/validation/test-class-amp-validation-manager.php @@ -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 )