Skip to content

Commit

Permalink
Use Fork Process strategy to replace BetterReflection strategy (#3634)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: 李铭昕 <[email protected]>
  • Loading branch information
3 people authored May 31, 2021
1 parent c0d2fc2 commit 8e89aa7
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions tests/AsyncQueueAspectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Hyperf\Di\Annotation\AnnotationCollector;
use Hyperf\Di\Annotation\Aspect;
use Hyperf\Di\Aop\Ast;
use Hyperf\Di\BetterReflectionManager;
use Hyperf\Di\ReflectionManager;
use Hyperf\Utils\ApplicationContext;
use Hyperf\Utils\Context;
use HyperfTest\AsyncQueue\Stub\FooProxy;
Expand All @@ -38,9 +38,12 @@ protected function tearDown(): void
{
Mockery::close();
Context::set(FooProxy::class, null);
BetterReflectionManager::clear();
ReflectionManager::clear();
}

/**
* @group NonCoroutine
*/
public function testNotAsyncMessage()
{
$container = $this->getContainer();
Expand All @@ -53,6 +56,9 @@ public function testNotAsyncMessage()
$this->assertSame([$id, $uuid, $data], Context::get(FooProxy::class));
}

/**
* @group NonCoroutine
*/
public function testAsyncMessage()
{
$container = $this->getContainer();
Expand All @@ -65,6 +71,9 @@ public function testAsyncMessage()
$this->assertSame($data, Context::get(FooProxy::class));
}

/**
* @group NonCoroutine
*/
public function testAsyncMessageVariadic()
{
$container = $this->getContainer();
Expand All @@ -82,20 +91,25 @@ protected function getContainer()
$container = Mockery::mock(ContainerInterface::class);
ApplicationContext::setContainer($container);

BetterReflectionManager::initClassReflector([__DIR__ . '/Stub/']);

$aspect = new Aspect();
$aspect->collectClass(AsyncQueueAspect::class);
AnnotationCollector::collectMethod(FooProxy::class, 'async', AsyncQueueMessage::class, new AsyncQueueMessage());
AnnotationCollector::collectMethod(FooProxy::class, 'variadic', AsyncQueueMessage::class, new AsyncQueueMessage());

$ast = new Ast();
$code = $ast->proxy(FooProxy::class);
if (! is_dir($dir = BASE_PATH . '/runtime/container/proxy/')) {
mkdir($dir, 0777, true);
$pid = pcntl_fork();
if (! $pid) {
$ast = new Ast();
$code = $ast->proxy(FooProxy::class);
if (! is_dir($dir = BASE_PATH . '/runtime/container/proxy/')) {
mkdir($dir, 0777, true);
}
file_put_contents($file = $dir . 'FooProxy.proxy.php', $code);
exit;
}
file_put_contents($file = $dir . 'FooProxy.proxy.php', $code);
require_once $file;

pcntl_wait($status);

require_once BASE_PATH . '/runtime/container/proxy/FooProxy.proxy.php';

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

0 comments on commit 8e89aa7

Please sign in to comment.