Skip to content

Commit

Permalink
Add test for RayAOP void return handling.
Browse files Browse the repository at this point in the history
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
koriym committed Dec 8, 2024
1 parent 865d6e6 commit 535b748
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/010-rayaop-void-return.phpt
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

0 comments on commit 535b748

Please sign in to comment.