|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TheCodingMachine\GraphQL\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Annotations\AnnotationException; |
|
6
|
|
|
use InvalidArgumentException; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Doctrine\Common\Annotations\AnnotationReader as DoctrineAnnotationReader; |
|
9
|
|
|
use ReflectionClass; |
|
10
|
|
|
use ReflectionMethod; |
|
11
|
|
|
use TheCodingMachine\GraphQL\Controllers\Annotations\Field; |
|
12
|
|
|
use TheCodingMachine\GraphQL\Controllers\Annotations\Type; |
|
13
|
|
|
use TheCodingMachine\GraphQL\Controllers\Fixtures\Annotations\ClassWithInvalidClassAnnotation; |
|
14
|
|
|
use TheCodingMachine\GraphQL\Controllers\Fixtures\Annotations\ClassWithInvalidTypeAnnotation; |
|
15
|
|
|
|
|
16
|
|
|
class AnnotationReaderTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
public function testBadConstructor() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
21
|
|
|
new AnnotationReader(new DoctrineAnnotationReader(), 'foo'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testStrictMode() |
|
25
|
|
|
{ |
|
26
|
|
|
$annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::STRICT_MODE, []); |
|
27
|
|
|
|
|
28
|
|
|
$this->expectException(AnnotationException::class); |
|
29
|
|
|
$annotationReader->getTypeAnnotation(new ReflectionClass(ClassWithInvalidClassAnnotation::class)); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testLaxModeWithBadAnnotation() |
|
33
|
|
|
{ |
|
34
|
|
|
$annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::LAX_MODE, []); |
|
35
|
|
|
|
|
36
|
|
|
$type = $annotationReader->getTypeAnnotation(new ReflectionClass(ClassWithInvalidClassAnnotation::class)); |
|
37
|
|
|
$this->assertNull($type); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testLaxModeWithSmellyAnnotation() |
|
41
|
|
|
{ |
|
42
|
|
|
$annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::LAX_MODE, []); |
|
43
|
|
|
|
|
44
|
|
|
$this->expectException(AnnotationException::class); |
|
45
|
|
|
$annotationReader->getTypeAnnotation(new ReflectionClass(ClassWithInvalidTypeAnnotation::class)); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testLaxModeWithBadAnnotationAndStrictNamespace() |
|
49
|
|
|
{ |
|
50
|
|
|
$annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::LAX_MODE, ['TheCodingMachine\\GraphQL\\Controllers\\Fixtures']); |
|
51
|
|
|
|
|
52
|
|
|
$this->expectException(AnnotationException::class); |
|
53
|
|
|
$annotationReader->getTypeAnnotation(new ReflectionClass(ClassWithInvalidClassAnnotation::class)); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testGetAnnotationsStrictMode() |
|
57
|
|
|
{ |
|
58
|
|
|
$annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::STRICT_MODE, []); |
|
59
|
|
|
|
|
60
|
|
|
$this->expectException(AnnotationException::class); |
|
61
|
|
|
$annotationReader->getClassAnnotations(new ReflectionClass(ClassWithInvalidClassAnnotation::class), Type::class); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testGetAnnotationsLaxModeWithBadAnnotation() |
|
65
|
|
|
{ |
|
66
|
|
|
$annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::LAX_MODE, []); |
|
67
|
|
|
|
|
68
|
|
|
$types = $annotationReader->getClassAnnotations(new ReflectionClass(ClassWithInvalidClassAnnotation::class), Type::class); |
|
69
|
|
|
$this->assertSame([], $types); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testGetAnnotationsLaxModeWithSmellyAnnotation() |
|
73
|
|
|
{ |
|
74
|
|
|
$annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::LAX_MODE, []); |
|
75
|
|
|
|
|
76
|
|
|
$this->expectException(AnnotationException::class); |
|
77
|
|
|
$annotationReader->getClassAnnotations(new ReflectionClass(ClassWithInvalidTypeAnnotation::class), Type::class); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testGetAnnotationsLaxModeWithBadAnnotationAndStrictNamespace() |
|
81
|
|
|
{ |
|
82
|
|
|
$annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::LAX_MODE, ['TheCodingMachine\\GraphQL\\Controllers\\Fixtures']); |
|
83
|
|
|
|
|
84
|
|
|
$this->expectException(AnnotationException::class); |
|
85
|
|
|
$annotationReader->getClassAnnotations(new ReflectionClass(ClassWithInvalidClassAnnotation::class), Type::class); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function testMethodStrictMode() |
|
89
|
|
|
{ |
|
90
|
|
|
$annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::STRICT_MODE, []); |
|
91
|
|
|
|
|
92
|
|
|
$this->expectException(AnnotationException::class); |
|
93
|
|
|
$annotationReader->getRequestAnnotation(new ReflectionMethod(ClassWithInvalidClassAnnotation::class, 'testMethod'), Field::class); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function testMethodLaxModeWithBadAnnotation() |
|
97
|
|
|
{ |
|
98
|
|
|
$annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::LAX_MODE, []); |
|
99
|
|
|
|
|
100
|
|
|
$type = $annotationReader->getRequestAnnotation(new ReflectionMethod(ClassWithInvalidClassAnnotation::class, 'testMethod'), Field::class); |
|
101
|
|
|
$this->assertNull($type); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function testMethodLaxModeWithSmellyAnnotation() |
|
105
|
|
|
{ |
|
106
|
|
|
$annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::LAX_MODE, []); |
|
107
|
|
|
|
|
108
|
|
|
$this->expectException(AnnotationException::class); |
|
109
|
|
|
$annotationReader->getRequestAnnotation(new ReflectionMethod(ClassWithInvalidTypeAnnotation::class, 'testMethod'), Field::class); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|