From 137a584dc593743a69aca8df5d5edda1c2a737cd Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Mon, 14 Sep 2026 17:53:28 +0800 Subject: [PATCH] test(PolymorphicClassDispatch): update regex pattern to use dynamic function IDs - Add reflection to access compiler's persistentFuncMap and literalStrings properties - Retrieve actual function ID and string ID for 'get_class' at runtime - Replace hardcoded regex values with dynamic IDs from compiler state - Ensure polymorphic get_class dispatch uses correct persistent function lookup - Maintain existing assertion logic while making test more robust to compiler changes --- phpunit/src/PolymorphicClassDispatchTest.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/phpunit/src/PolymorphicClassDispatchTest.php b/phpunit/src/PolymorphicClassDispatchTest.php index d9ac232b..b6f69894 100644 --- a/phpunit/src/PolymorphicClassDispatchTest.php +++ b/phpunit/src/PolymorphicClassDispatchTest.php @@ -25,8 +25,17 @@ final class PolymorphicClassDispatchTest extends BaseTest // Polymorphic get_class() must NOT fold or blindly invoke unchecked C++ helper; // it must use runtime php::call to enforce PHP argument semantics (TypeError on null) + $persistentFunctions = (new \ReflectionProperty($compiler, 'persistentFuncMap'))->getValue($compiler); + $literalStrings = (new \ReflectionProperty($compiler, 'literalStrings'))->getValue($compiler); + self::assertArrayHasKey('get_class', $persistentFunctions); + self::assertArrayHasKey('get_class', $literalStrings); self::assertMatchesRegularExpression( - "/php_getpolymorphicclass\(\) \{.*?tmp_var_\d+ = \(php::call\(get_persistent_func\(PersistentFuncId\{0\}, get_str\(3\)\), php::VarList\{animal\}\)\);/s", + sprintf( + '/php_getpolymorphicclass\(\) \{.*?tmp_var_\d+ = \(php::call\(get_persistent_func' + . '\(PersistentFuncId\{%d\}, get_str\(%d\)\), php::VarList\{animal\}\)\);/s', + $persistentFunctions['get_class'], + $literalStrings['get_class'], + ), $code, );