From ecd73326d73a0db4ff39ffb259c9ca5c95720b8a Mon Sep 17 00:00:00 2001 From: Yurun Date: Thu, 21 Mar 2024 19:49:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/unit/Component/Aop/Aop/PriorityAop.php | 47 +++++++++++++++++++ .../Aop/Classes/TestPriorityClass.php | 15 ++++++ tests/unit/Component/Tests/AopTest.php | 10 ++++ 3 files changed, 72 insertions(+) create mode 100644 tests/unit/Component/Aop/Aop/PriorityAop.php create mode 100644 tests/unit/Component/Aop/Classes/TestPriorityClass.php diff --git a/tests/unit/Component/Aop/Aop/PriorityAop.php b/tests/unit/Component/Aop/Aop/PriorityAop.php new file mode 100644 index 0000000000..a05601d3bf --- /dev/null +++ b/tests/unit/Component/Aop/Aop/PriorityAop.php @@ -0,0 +1,47 @@ +getArgs(); + $args[0][] = 1; + $joinPoint->proceed(); + + return 1; + } + + #[Around] + #[PointCut(allow: ['Imi\\Test\\Component\\Aop\\Classes\\TestPriorityClass::test'], priority: 500)] + public function aop2(AroundJoinPoint $joinPoint): mixed + { + $args = $joinPoint->getArgs(); + $args[0][] = 2; + $joinPoint->proceed(); + + return 2; + } + + #[Around] + #[PointCut(allow: ['Imi\\Test\\Component\\Aop\\Classes\\TestPriorityClass::test'], priority: 1500)] + public function aop3(AroundJoinPoint $joinPoint): mixed + { + $args = $joinPoint->getArgs(); + $args[0][] = 3; + $joinPoint->proceed(); + + return 3; + } +} diff --git a/tests/unit/Component/Aop/Classes/TestPriorityClass.php b/tests/unit/Component/Aop/Classes/TestPriorityClass.php new file mode 100644 index 0000000000..a2c3bf0ae3 --- /dev/null +++ b/tests/unit/Component/Aop/Classes/TestPriorityClass.php @@ -0,0 +1,15 @@ +assertNotNull($throwable); $this->assertEquals('test', $throwable->getMessage()); } + + public function testPriority(): void + { + $test = App::getBean(TestPriorityClass::class); + $list = []; + $result = $test->test($list); + $this->assertEquals(3, $result); + $this->assertEquals([3, 1, 2, 0], $list); + } }