Skip to content

Commit 17ee795

Browse files
authored
Added test case for checking refcount for aop pipeline. (#3088)
* Added test case for checking refcount for aop pipeline. * Update
1 parent b4c11d4 commit 17ee795

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

tests/Aop/PipelineTest.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Hyperf.
6+
*
7+
* @link https://www.hyperf.io
8+
* @document https://hyperf.wiki
9+
* @contact [email protected]
10+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+
*/
12+
namespace HyperfTest\Di\Aop;
13+
14+
use Hyperf\Di\Aop\Pipeline;
15+
use Hyperf\Di\Aop\ProceedingJoinPoint;
16+
use HyperfTest\Di\Stub\Aspect\NoProcessAspect;
17+
use Mockery;
18+
use PHPUnit\Framework\TestCase;
19+
use Psr\Container\ContainerInterface;
20+
21+
/**
22+
* @internal
23+
* @coversNothing
24+
*/
25+
class PipelineTest extends TestCase
26+
{
27+
protected function tearDown(): void
28+
{
29+
Mockery::close();
30+
}
31+
32+
public function testRefcountForPipelineCarry()
33+
{
34+
$container = Mockery::mock(ContainerInterface::class);
35+
$container->shouldReceive('get')->with(NoProcessAspect::class)->andReturn(new NoProcessAspect());
36+
$pipeline = new Pipeline($container);
37+
38+
$point = new ProceedingJoinPoint(function () {
39+
}, 'Foo', 'call', []);
40+
41+
$res = $pipeline->via('process')->through([
42+
NoProcessAspect::class,
43+
])->send($point)->then(function () {
44+
});
45+
46+
$this->assertTrue($res);
47+
48+
ob_start();
49+
debug_zval_dump($pipeline);
50+
$data = ob_get_clean();
51+
52+
preg_match('/refcount\((\d+)\)/U', $data, $res);
53+
$this->assertEquals(2, $res[1]);
54+
}
55+
}

tests/Stub/Aspect/NoProcessAspect.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Hyperf.
6+
*
7+
* @link https://www.hyperf.io
8+
* @document https://hyperf.wiki
9+
* @contact [email protected]
10+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+
*/
12+
namespace HyperfTest\Di\Stub\Aspect;
13+
14+
use Hyperf\Di\Aop\ProceedingJoinPoint;
15+
16+
class NoProcessAspect
17+
{
18+
public function process(ProceedingJoinPoint $proceedingJoinPoint)
19+
{
20+
return true;
21+
}
22+
}

0 commit comments

Comments
 (0)