|
5 | 5 | namespace GraphQLTests\Doctrine\Attribute\Reader;
|
6 | 6 |
|
7 | 7 | use GraphQL\Doctrine\Attribute\Argument;
|
| 8 | +use GraphQL\Doctrine\Attribute\Exclude; |
8 | 9 | use GraphQL\Doctrine\Attribute\Field;
|
9 | 10 | use GraphQL\Doctrine\Attribute\Filter;
|
10 | 11 | use GraphQL\Doctrine\Attribute\FilterGroupCondition;
|
|
17 | 18 | use ReflectionClass;
|
18 | 19 | use ReflectionMethod;
|
19 | 20 | use ReflectionProperty;
|
| 21 | +use ReturnTypeWillChange; |
20 | 22 |
|
21 | 23 | class ReaderTest extends TestCase
|
22 | 24 | {
|
@@ -80,4 +82,37 @@ public function testGetParameterAttribute(): void
|
80 | 82 | $this->reader->getAttribute((new ReflectionMethod(User::class, 'getPosts'))->getParameters()[0], Argument::class)
|
81 | 83 | );
|
82 | 84 | }
|
| 85 | + |
| 86 | + public function testWillThrowIfUniqueAttributeIsUsedMultipleTimes(): void |
| 87 | + { |
| 88 | + $mock = new class() { |
| 89 | + #[Exclude] |
| 90 | + /** @phpstan-ignore-next-line */ |
| 91 | + #[Exclude] |
| 92 | + /** |
| 93 | + * @phpstan-ignore-next-line |
| 94 | + */ |
| 95 | + private $foo; |
| 96 | + }; |
| 97 | + |
| 98 | + $this->expectExceptionMessage('Attribute "GraphQL\Doctrine\Attribute\Exclude" must not be repeated'); |
| 99 | + $this->reader->getAttribute(new ReflectionProperty($mock, 'foo'), Exclude::class); |
| 100 | + } |
| 101 | + |
| 102 | + public function testWillThrowIfReaderIsUsedWithOtherAttributes(): void |
| 103 | + { |
| 104 | + $mock = new class() { |
| 105 | + /** |
| 106 | + * @phpstan-ignore-next-line |
| 107 | + */ |
| 108 | + #[ReturnTypeWillChange] |
| 109 | + private function foo(): void |
| 110 | + { |
| 111 | + } |
| 112 | + }; |
| 113 | + |
| 114 | + $this->expectExceptionMessage('GraphQL\Doctrine\Attribute\Reader\Reader cannot be used for attribute than are not part of `ecodev/graphql-doctrine`.'); |
| 115 | + // @phpstan-ignore-next-line |
| 116 | + $this->reader->getAttribute(new ReflectionMethod($mock, 'foo'), ReturnTypeWillChange::class); |
| 117 | + } |
83 | 118 | }
|
0 commit comments