Skip to content

Commit 535b748

Browse files
committed
Add test for RayAOP void return handling.
This test ensures that the interception works correctly with methods that have no explicit return statement and those with an empty return. It validates that the interceptor processes both void and empty return methods as expected, returning null in each case.
1 parent 865d6e6 commit 535b748

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/010-rayaop-void-return.phpt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--TEST--
2+
RayAOP void return handling test
3+
--FILE--
4+
<?php
5+
class VoidTestInterceptor implements Ray\Aop\MethodInterceptorInterface {
6+
public function intercept(object $object, string $method, array $params): mixed {
7+
echo "Before void method\n";
8+
$result = $object->$method(...$params);
9+
echo "After void method\n";
10+
return $result;
11+
}
12+
}
13+
14+
class TestClass {
15+
public function voidMethod() {
16+
echo "Executing void method\n";
17+
// 明示的なreturnなし
18+
}
19+
20+
public function emptyReturnMethod() {
21+
echo "Executing empty return method\n";
22+
return; // 明示的な空return
23+
}
24+
}
25+
26+
method_intercept_init();
27+
method_intercept(TestClass::class, 'voidMethod', new VoidTestInterceptor());
28+
method_intercept(TestClass::class, 'emptyReturnMethod', new VoidTestInterceptor());
29+
method_intercept_enable(true);
30+
31+
$test = new TestClass();
32+
33+
echo "Testing void method:\n";
34+
$result = $test->voidMethod();
35+
var_dump($result);
36+
37+
echo "\nTesting empty return method:\n";
38+
$result = $test->emptyReturnMethod();
39+
var_dump($result);
40+
41+
--EXPECT--
42+
Testing void method:
43+
Before void method
44+
Executing void method
45+
After void method
46+
NULL
47+
48+
Testing empty return method:
49+
Before void method
50+
Executing empty return method
51+
After void method
52+
NULL

0 commit comments

Comments
 (0)