Skip to content

Commit 8e89aa7

Browse files
Use Fork Process strategy to replace BetterReflection strategy (#3634)
* 2.2 * Format code * optimization * ast parser * temp data of scan process * replace BetterReflection strategy * Optimized code * Update Scanner.php * Fixed phpunit * Fixed phpunit * replace BetterReflection strategy * Update AsyncQueueAspectTest.php * optimization * Update InjectTest.php * Update CHANGELOG-2.2.md Co-authored-by: assert <zhangchengming@kkguan.com> Co-authored-by: 李铭昕 <715557344@qq.com>
1 parent c0d2fc2 commit 8e89aa7

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

tests/AsyncQueueAspectTest.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Hyperf\Di\Annotation\AnnotationCollector;
2121
use Hyperf\Di\Annotation\Aspect;
2222
use Hyperf\Di\Aop\Ast;
23-
use Hyperf\Di\BetterReflectionManager;
23+
use Hyperf\Di\ReflectionManager;
2424
use Hyperf\Utils\ApplicationContext;
2525
use Hyperf\Utils\Context;
2626
use HyperfTest\AsyncQueue\Stub\FooProxy;
@@ -38,9 +38,12 @@ protected function tearDown(): void
3838
{
3939
Mockery::close();
4040
Context::set(FooProxy::class, null);
41-
BetterReflectionManager::clear();
41+
ReflectionManager::clear();
4242
}
4343

44+
/**
45+
* @group NonCoroutine
46+
*/
4447
public function testNotAsyncMessage()
4548
{
4649
$container = $this->getContainer();
@@ -53,6 +56,9 @@ public function testNotAsyncMessage()
5356
$this->assertSame([$id, $uuid, $data], Context::get(FooProxy::class));
5457
}
5558

59+
/**
60+
* @group NonCoroutine
61+
*/
5662
public function testAsyncMessage()
5763
{
5864
$container = $this->getContainer();
@@ -65,6 +71,9 @@ public function testAsyncMessage()
6571
$this->assertSame($data, Context::get(FooProxy::class));
6672
}
6773

74+
/**
75+
* @group NonCoroutine
76+
*/
6877
public function testAsyncMessageVariadic()
6978
{
7079
$container = $this->getContainer();
@@ -82,20 +91,25 @@ protected function getContainer()
8291
$container = Mockery::mock(ContainerInterface::class);
8392
ApplicationContext::setContainer($container);
8493

85-
BetterReflectionManager::initClassReflector([__DIR__ . '/Stub/']);
86-
8794
$aspect = new Aspect();
8895
$aspect->collectClass(AsyncQueueAspect::class);
8996
AnnotationCollector::collectMethod(FooProxy::class, 'async', AsyncQueueMessage::class, new AsyncQueueMessage());
9097
AnnotationCollector::collectMethod(FooProxy::class, 'variadic', AsyncQueueMessage::class, new AsyncQueueMessage());
9198

92-
$ast = new Ast();
93-
$code = $ast->proxy(FooProxy::class);
94-
if (! is_dir($dir = BASE_PATH . '/runtime/container/proxy/')) {
95-
mkdir($dir, 0777, true);
99+
$pid = pcntl_fork();
100+
if (! $pid) {
101+
$ast = new Ast();
102+
$code = $ast->proxy(FooProxy::class);
103+
if (! is_dir($dir = BASE_PATH . '/runtime/container/proxy/')) {
104+
mkdir($dir, 0777, true);
105+
}
106+
file_put_contents($file = $dir . 'FooProxy.proxy.php', $code);
107+
exit;
96108
}
97-
file_put_contents($file = $dir . 'FooProxy.proxy.php', $code);
98-
require_once $file;
109+
110+
pcntl_wait($status);
111+
112+
require_once BASE_PATH . '/runtime/container/proxy/FooProxy.proxy.php';
99113

100114
$container->shouldReceive('get')->with(FooProxy::class)->andReturn(new FooProxy());
101115
$container->shouldReceive('get')->with(AsyncQueueAspect::class)->andReturnUsing(function ($_) use ($container) {

0 commit comments

Comments
 (0)