generated from koriym/ext-helloworld
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
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,52 @@ | ||
--TEST-- | ||
RayAOP void return handling test | ||
--FILE-- | ||
<?php | ||
class VoidTestInterceptor implements Ray\Aop\MethodInterceptorInterface { | ||
public function intercept(object $object, string $method, array $params): mixed { | ||
echo "Before void method\n"; | ||
$result = $object->$method(...$params); | ||
echo "After void method\n"; | ||
return $result; | ||
} | ||
} | ||
|
||
class TestClass { | ||
public function voidMethod() { | ||
echo "Executing void method\n"; | ||
// 明示的なreturnなし | ||
} | ||
|
||
public function emptyReturnMethod() { | ||
echo "Executing empty return method\n"; | ||
return; // 明示的な空return | ||
} | ||
} | ||
|
||
method_intercept_init(); | ||
method_intercept(TestClass::class, 'voidMethod', new VoidTestInterceptor()); | ||
method_intercept(TestClass::class, 'emptyReturnMethod', new VoidTestInterceptor()); | ||
method_intercept_enable(true); | ||
|
||
$test = new TestClass(); | ||
|
||
echo "Testing void method:\n"; | ||
$result = $test->voidMethod(); | ||
var_dump($result); | ||
|
||
echo "\nTesting empty return method:\n"; | ||
$result = $test->emptyReturnMethod(); | ||
var_dump($result); | ||
|
||
--EXPECT-- | ||
Testing void method: | ||
Before void method | ||
Executing void method | ||
After void method | ||
NULL | ||
|
||
Testing empty return method: | ||
Before void method | ||
Executing empty return method | ||
After void method | ||
NULL |