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
master
韩天峰 4 weeks ago
parent 1b79fcd2b4
commit 137a584dc5
  1. 11
      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,
);

Loading…
Cancel
Save