-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests of instrumentation of functions/methods in namespace (#167)
- Loading branch information
Showing
2 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
prod/native/extension/phpt/tests/instrumentation_user_func_namespace.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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-- | ||
<?php | ||
declare(strict_types=1); | ||
|
||
|
||
namespace SomeNameSpace; | ||
|
||
function userspace($arg1, $arg2, $arg3) { | ||
echo "* userspace() body start.\n"; | ||
echo "args:\n"; | ||
var_dump(func_get_args()); | ||
echo "* userspace() body end\n"; | ||
return "userspace_rv"; | ||
} | ||
|
||
elastic_otel_hook(null, "somenamespace\\userspace", function () { | ||
echo "*** prehook userspace()\n"; | ||
echo "args:\n"; | ||
var_dump(func_get_args()); | ||
}, function () { | ||
echo "*** posthook userspace()\n"; | ||
echo "args:\n"; | ||
var_dump(func_get_args()); | ||
}); | ||
|
||
var_dump(userspace("first", 2, 3)); | ||
|
||
echo "Test completed\n"; | ||
?> | ||
--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 |
106 changes: 106 additions & 0 deletions
106
prod/native/extension/phpt/tests/instrumentation_user_method_namespace.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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-- | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace SomeNameSpace; | ||
class TestClass { | ||
function userspace($arg1, $arg2, $arg3) { | ||
echo "* userspace() body start.\n"; | ||
echo "args:\n"; | ||
var_dump(func_get_args()); | ||
echo "* userspace() body end\n"; | ||
return "userspace_rv"; | ||
} | ||
} | ||
|
||
elastic_otel_hook("somenamespace\\testclass", "userspace", function () { | ||
echo "*** prehook userspace()\n"; | ||
echo "args:\n"; | ||
var_dump(func_get_args()); | ||
return [0 => "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 |