Skip to content

Commit

Permalink
增加测试
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Mar 21, 2024
1 parent 739a62e commit ecd7332
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/unit/Component/Aop/Aop/PriorityAop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Imi\Test\Component\Aop\Aop;

use Imi\Aop\Annotation\Around;
use Imi\Aop\Annotation\Aspect;
use Imi\Aop\Annotation\PointCut;
use Imi\Aop\AroundJoinPoint;

#[Aspect(1000)]
class PriorityAop
{
#[Around]
#[PointCut(allow: ['Imi\\Test\\Component\\Aop\\Classes\\TestPriorityClass::test'])]
public function aop1(AroundJoinPoint $joinPoint): mixed
{
$args = $joinPoint->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;
}
}
15 changes: 15 additions & 0 deletions tests/unit/Component/Aop/Classes/TestPriorityClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Imi\Test\Component\Aop\Classes;

class TestPriorityClass
{
public function test(array &$list): int
{
$list[] = 0;

return 0;
}
}
10 changes: 10 additions & 0 deletions tests/unit/Component/Tests/AopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Imi\App;
use Imi\Test\BaseTest;
use Imi\Test\Component\Aop\Classes\TestPriorityClass;

/**
* @testdox Aop
Expand Down Expand Up @@ -87,4 +88,13 @@ public function testAfterThrowing(): void
$this->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);
}
}

0 comments on commit ecd7332

Please sign in to comment.