|
13 | 13 |
|
14 | 14 | use Hyperf\Contract\ContainerInterface;
|
15 | 15 | use Hyperf\Di\Annotation\AnnotationReader;
|
| 16 | +use Hyperf\Di\Annotation\Inject; |
16 | 17 | use Hyperf\Di\Annotation\ScanConfig;
|
17 | 18 | use Hyperf\Di\Annotation\Scanner;
|
18 | 19 | use Hyperf\Di\Aop\Ast;
|
19 | 20 | use Hyperf\Di\BetterReflectionManager;
|
20 | 21 | use Hyperf\Di\ClassLoader;
|
| 22 | +use Hyperf\Di\Exception\AnnotationException; |
21 | 23 | use Hyperf\Di\Exception\NotFoundException;
|
22 | 24 | use Hyperf\Utils\ApplicationContext;
|
23 | 25 | use HyperfTest\Di\ExceptionStub\DemoInjectException;
|
24 | 26 | use HyperfTest\Di\Stub\AnnotationCollector;
|
25 | 27 | use HyperfTest\Di\Stub\AspectCollector;
|
26 | 28 | use HyperfTest\Di\Stub\Demo;
|
27 | 29 | use HyperfTest\Di\Stub\DemoInject;
|
| 30 | +use HyperfTest\Di\Stub\EmptyVarValue; |
28 | 31 | use Mockery;
|
29 | 32 | use PHPUnit\Framework\TestCase;
|
30 | 33 |
|
@@ -76,6 +79,26 @@ public function testInjectException()
|
76 | 79 | }
|
77 | 80 | }
|
78 | 81 |
|
| 82 | + public function testInjectNotInitReflector() |
| 83 | + { |
| 84 | + $this->expectException(AnnotationException::class); |
| 85 | + $this->expectExceptionMessage('The @Inject value is invalid for HyperfTest\Di\Stub\EmptyVarValue->demo. Because The class reflector object does not init yet'); |
| 86 | + |
| 87 | + $inject = new Inject(); |
| 88 | + $inject->collectProperty(EmptyVarValue::class, 'demo'); |
| 89 | + } |
| 90 | + |
| 91 | + public function testInjectEmptyVar() |
| 92 | + { |
| 93 | + $this->expectException(AnnotationException::class); |
| 94 | + $this->expectExceptionMessage('The @Inject value is invalid for HyperfTest\Di\Stub\EmptyVarValue->demo. Because Argument 1 passed to Roave\BetterReflection\TypesFinder\FindPropertyType::Roave\BetterReflection\TypesFinder\{closure}() must be an instance of phpDocumentor\Reflection\DocBlock\Tags\Var_, instance of phpDocumentor\Reflection\DocBlock\Tags\InvalidTag given'); |
| 95 | + |
| 96 | + BetterReflectionManager::initClassReflector([__DIR__ . '/Stub']); |
| 97 | + |
| 98 | + $inject = new Inject(); |
| 99 | + $inject->collectProperty(EmptyVarValue::class, 'demo'); |
| 100 | + } |
| 101 | + |
79 | 102 | protected function getContainer()
|
80 | 103 | {
|
81 | 104 | $container = Mockery::mock(ContainerInterface::class);
|
|
0 commit comments