diff --git a/tests/GeneratedFunctionSignatureTest.php b/tests/GeneratedFunctionSignatureTest.php new file mode 100644 index 00000000..d011fe06 --- /dev/null +++ b/tests/GeneratedFunctionSignatureTest.php @@ -0,0 +1,77 @@ + + */ + public static function generatedFunctions(): iterable + { + $file = sprintf( + '%s/../generated/%d.%d/functionsList.php', + __DIR__, + PHP_MAJOR_VERSION, + PHP_MINOR_VERSION + ); + + $functions = require $file; + if (!is_array($functions)) { + throw new RuntimeException(sprintf('Generated function list %s must return an array.', $file)); + } + + foreach ($functions as $functionName) { + yield $functionName => [$functionName]; + } + } + + /** + * @dataProvider generatedFunctions + */ + public function testParametersMatchNativeFunction(string $functionName): void + { + if (!function_exists($functionName)) { + self::markTestSkipped(sprintf('The %s extension is not loaded.', $functionName)); + } + + $nativeFunction = new ReflectionFunction($functionName); + $safeFunction = new ReflectionFunction('Safe\\' . $functionName); + + self::assertSame( + self::parameterSignatures($nativeFunction), + self::parameterSignatures($safeFunction) + ); + } + + /** + * @return list + */ + private static function parameterSignatures(ReflectionFunction $function): array + { + return array_map( + static function (ReflectionParameter $parameter): array { + return [ + 'name' => $parameter->getName(), + #'type' => (string) $parameter->getType(), + 'allowsNull' => $parameter->allowsNull(), + 'byReference' => $parameter->isPassedByReference(), + 'variadic' => $parameter->isVariadic(), + 'optional' => $parameter->isOptional(), + 'default' => $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null, + ]; + }, + $function->getParameters() + ); + } +}