|
20 | 20 | use Hyperf\AsyncQueue\Environment; |
21 | 21 | use Hyperf\Context\ApplicationContext; |
22 | 22 | use Hyperf\Context\Context; |
| 23 | +use Hyperf\Coroutine\Waiter; |
23 | 24 | use Hyperf\Di\Annotation\AnnotationCollector; |
24 | 25 | use Hyperf\Di\Annotation\Aspect; |
25 | 26 | use Hyperf\Di\Aop\Ast; |
26 | 27 | use Hyperf\Di\ReflectionManager; |
27 | 28 | use HyperfTest\AsyncQueue\Stub\FooProxy; |
| 29 | +use HyperfTest\AsyncQueue\Stub\FooService; |
28 | 30 | use Mockery; |
29 | 31 | use PHPUnit\Framework\Attributes\CoversNothing; |
30 | 32 | use PHPUnit\Framework\Attributes\Group; |
31 | 33 | use PHPUnit\Framework\TestCase; |
32 | 34 | use Psr\Container\ContainerInterface; |
33 | 35 |
|
| 36 | +use function Hyperf\Coroutine\wait; |
| 37 | + |
34 | 38 | /** |
35 | 39 | * @internal |
36 | 40 | * @coversNothing |
@@ -84,6 +88,28 @@ public function testAsyncMessageVariadic() |
84 | 88 | $this->assertSame([$id, $uuid, $data], Context::get(FooProxy::class)); |
85 | 89 | } |
86 | 90 |
|
| 91 | + public function testAnnotationJob() |
| 92 | + { |
| 93 | + $container = Mockery::mock(ContainerInterface::class); |
| 94 | + ApplicationContext::setContainer($container); |
| 95 | + $container->shouldReceive('get')->with(Waiter::class)->andReturn(new Waiter()); |
| 96 | + |
| 97 | + wait(function () use ($container) { |
| 98 | + $container->shouldReceive('get')->with(FooService::class)->andReturn(new FooService()); |
| 99 | + $container->shouldReceive('get')->with(Environment::class)->andReturn(new Environment()); |
| 100 | + |
| 101 | + $job = new AnnotationJob(FooService::class, 'test', []); |
| 102 | + $job->handle(); |
| 103 | + |
| 104 | + $this->assertSame(1, Context::get(FooService::class . '::test')); |
| 105 | + |
| 106 | + $job = new AnnotationJob(FooService::class, 'foo', []); |
| 107 | + $job->handle(); |
| 108 | + |
| 109 | + $this->assertSame(1, Context::get(FooService::class . '::foo')); |
| 110 | + }); |
| 111 | + } |
| 112 | + |
87 | 113 | protected function getContainer() |
88 | 114 | { |
89 | 115 | $container = Mockery::mock(ContainerInterface::class); |
|
0 commit comments