|
9 | 9 | use ReflectionMethod;
|
10 | 10 | use TheCodingMachine\GraphQLite\Annotations\Autowire;
|
11 | 11 | use TheCodingMachine\GraphQLite\Annotations\Exceptions\ClassNotFoundException;
|
| 12 | +use TheCodingMachine\GraphQLite\Annotations\Exceptions\InvalidParameterException; |
12 | 13 | use TheCodingMachine\GraphQLite\Annotations\Field;
|
13 | 14 | use TheCodingMachine\GraphQLite\Annotations\Security;
|
14 | 15 | use TheCodingMachine\GraphQLite\Annotations\Type;
|
15 | 16 | use TheCodingMachine\GraphQLite\Fixtures\Annotations\ClassWithInvalidClassAnnotation;
|
16 | 17 | use TheCodingMachine\GraphQLite\Fixtures\Annotations\ClassWithInvalidExtendTypeAnnotation;
|
17 | 18 | use TheCodingMachine\GraphQLite\Fixtures\Annotations\ClassWithInvalidTypeAnnotation;
|
| 19 | +use TheCodingMachine\GraphQLite\Fixtures\Annotations\ClassWithTargetMethodParameterAnnotation; |
| 20 | +use TheCodingMachine\GraphQLite\Fixtures\Annotations\TargetMethodParameterAnnotation; |
18 | 21 | use TheCodingMachine\GraphQLite\Fixtures\Attributes\TestType;
|
19 | 22 |
|
20 | 23 | class AnnotationReaderTest extends TestCase
|
@@ -126,6 +129,32 @@ public function testPhp8AttributeParameterAnnotations(): void
|
126 | 129 | $this->assertInstanceOf(Autowire::class, $parameterAnnotations['dao']->getAnnotationByType(Autowire::class));
|
127 | 130 | }
|
128 | 131 |
|
| 132 | + /** |
| 133 | + * This functionality can be dropped with next major release (8.0) with added explicit deprecations before release. |
| 134 | + */ |
| 135 | + public function testPhp8AttributeParameterAnnotationsForTargetMethod(): void |
| 136 | + { |
| 137 | + $annotationReader = new AnnotationReader(); |
| 138 | + |
| 139 | + $parameterAnnotations = $annotationReader->getParameterAnnotationsPerParameter((new ReflectionMethod(ClassWithTargetMethodParameterAnnotation::class, 'method'))->getParameters()); |
| 140 | + |
| 141 | + $this->assertInstanceOf(TargetMethodParameterAnnotation::class, $parameterAnnotations['bar']->getAnnotationByType(TargetMethodParameterAnnotation::class)); |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * This functionality can be dropped with next major release (8.0) with added explicit deprecations before release. |
| 146 | + */ |
| 147 | + public function testPhp8AttributeParameterAnnotationsForTargetMethodWithInvalidTargetParameter(): void |
| 148 | + { |
| 149 | + $annotationReader = new AnnotationReader(); |
| 150 | + |
| 151 | + $this->expectException(InvalidParameterException::class); |
| 152 | + $this->expectExceptionMessage('Parameter "unexistent" declared in annotation "TheCodingMachine\GraphQLite\Fixtures\Annotations\TargetMethodParameterAnnotation" of method "TheCodingMachine\GraphQLite\Fixtures\Annotations\ClassWithTargetMethodParameterAnnotation::methodWithInvalidAnnotation()" does not exist.'); |
| 153 | + |
| 154 | + $annotationReader->getParameterAnnotationsPerParameter((new ReflectionMethod(ClassWithTargetMethodParameterAnnotation::class, 'methodWithInvalidAnnotation'))->getParameters()); |
| 155 | + } |
| 156 | + |
| 157 | + /** @noinspection PhpUnusedPrivateMethodInspection Used in {@see testPhp8AttributeParameterAnnotations} */ |
129 | 158 | private function method1(
|
130 | 159 | #[Autowire('myService')]
|
131 | 160 | $dao,
|
|
0 commit comments