From ebbf97a701da0ba2f89e3dfe5fef1272598cf5b2 Mon Sep 17 00:00:00 2001 From: Pawel Filipczak Date: Wed, 12 Feb 2025 15:47:06 +0100 Subject: [PATCH] Tests of instrumentation of functions/methods in namespace (#167) --- .../instrumentation_user_func_namespace.phpt | 100 +++++++++++++++++ ...instrumentation_user_method_namespace.phpt | 106 ++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 prod/native/extension/phpt/tests/instrumentation_user_func_namespace.phpt create mode 100644 prod/native/extension/phpt/tests/instrumentation_user_method_namespace.phpt diff --git a/prod/native/extension/phpt/tests/instrumentation_user_func_namespace.phpt b/prod/native/extension/phpt/tests/instrumentation_user_func_namespace.phpt new file mode 100644 index 0000000..10230f0 --- /dev/null +++ b/prod/native/extension/phpt/tests/instrumentation_user_func_namespace.phpt @@ -0,0 +1,100 @@ +--TEST-- +instrumentation - user func in namespace +--ENV-- +ELASTIC_OTEL_LOG_LEVEL_STDERR=INFO +--INI-- +extension=/elastic/elastic_otel_php.so +elastic_otel.bootstrap_php_part_file={PWD}/includes/bootstrap_mock.inc +--FILE-- + +--EXPECTF-- +*** prehook userspace() +args: +array(6) { + [0]=> + NULL + [1]=> + array(3) { + [0]=> + string(5) "first" + [1]=> + int(2) + [2]=> + int(3) + } + [2]=> + NULL + [3]=> + string(%d) "SomeNameSpace\userspace" + [4]=> + string(%d) "%a/instrumentation_user_func_namespace.php" + [5]=> + int(7) +} +* userspace() body start. +args: +array(3) { + [0]=> + string(5) "first" + [1]=> + int(2) + [2]=> + int(3) +} +* userspace() body end +*** posthook userspace() +args: +array(8) { + [0]=> + NULL + [1]=> + array(3) { + [0]=> + string(5) "first" + [1]=> + int(2) + [2]=> + int(3) + } + [2]=> + string(12) "userspace_rv" + [3]=> + NULL + [4]=> + NULL + [5]=> + string(%d) "SomeNameSpace\userspace" + [6]=> + string(%d) "%a/instrumentation_user_func_namespace.php" + [7]=> + int(7) +} +string(12) "userspace_rv" +Test completed \ No newline at end of file diff --git a/prod/native/extension/phpt/tests/instrumentation_user_method_namespace.phpt b/prod/native/extension/phpt/tests/instrumentation_user_method_namespace.phpt new file mode 100644 index 0000000..26ea69f --- /dev/null +++ b/prod/native/extension/phpt/tests/instrumentation_user_method_namespace.phpt @@ -0,0 +1,106 @@ +--TEST-- +instrumentation - user method in namespace - args post processing and return value replacement +--ENV-- +ELASTIC_OTEL_LOG_LEVEL_STDERR=INFO +--INI-- +extension=/elastic/elastic_otel_php.so +elastic_otel.bootstrap_php_part_file={PWD}/includes/bootstrap_mock.inc +--FILE-- + "replaced_first_argument"]; + }, function () : string { + echo "*** posthook userspace()\n"; + echo "args:\n"; + var_dump(func_get_args()); + return "replaced_return_value"; +}); + +$obj = new TestClass; + +var_dump($obj->userspace("first", 2, 3)); + +echo "Test completed\n"; +?> +--EXPECTF-- +*** prehook userspace() +args: +array(6) { + [0]=> + object(SomeNameSpace\TestClass)#%d (0) { + } + [1]=> + array(3) { + [0]=> + string(5) "first" + [1]=> + int(2) + [2]=> + int(3) + } + [2]=> + string(23) "SomeNameSpace\TestClass" + [3]=> + string(9) "userspace" + [4]=> + string(%d) "%a/instrumentation_user_method_namespace.php" + [5]=> + int(6) +} +* userspace() body start. +args: +array(3) { + [0]=> + string(23) "replaced_first_argument" + [1]=> + int(2) + [2]=> + int(3) +} +* userspace() body end +*** posthook userspace() +args: +array(8) { + [0]=> + object(SomeNameSpace\TestClass)#%d (0) { + } + [1]=> + array(3) { + [0]=> + string(23) "replaced_first_argument" + [1]=> + int(2) + [2]=> + int(3) + } + [2]=> + string(12) "userspace_rv" + [3]=> + NULL + [4]=> + string(23) "SomeNameSpace\TestClass" + [5]=> + string(9) "userspace" + [6]=> + string(%d) "%a/instrumentation_user_method_namespace.php" + [7]=> + int(6) +} +string(21) "replaced_return_value" +Test completed \ No newline at end of file