|
| 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 | + |
| 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 | +} |
0 commit comments