Passed
Pull Request — master (#72)
by David
01:43
created

testLaxModeWithBadAnnotationAndStrictNamespace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
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 TheCodingMachine\GraphQL\Controllers\Annotations\Type;
11
use TheCodingMachine\GraphQL\Controllers\Fixtures\Annotations\ClassWithInvalidClassAnnotation;
12
use TheCodingMachine\GraphQL\Controllers\Fixtures\Annotations\ClassWithInvalidTypeAnnotation;
13
14
class AnnotationReaderTest extends TestCase
15
{
16
    public function testBadConstructor()
17
    {
18
        $this->expectException(InvalidArgumentException::class);
19
        new AnnotationReader(new DoctrineAnnotationReader(), 'foo');
20
    }
21
22
    public function testStrictMode()
23
    {
24
        $annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::STRICT_MODE, []);
25
26
        $this->expectException(AnnotationException::class);
27
        $annotationReader->getTypeAnnotation(new ReflectionClass(ClassWithInvalidClassAnnotation::class));
28
    }
29
30
    public function testLaxModeWithBadAnnotation()
31
    {
32
        $annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::LAX_MODE, []);
33
34
        $type = $annotationReader->getTypeAnnotation(new ReflectionClass(ClassWithInvalidClassAnnotation::class));
35
        $this->assertNull($type);
36
    }
37
38
    public function testLaxModeWithSmellyAnnotation()
39
    {
40
        $annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::LAX_MODE, []);
41
42
        $this->expectException(AnnotationException::class);
43
        $annotationReader->getTypeAnnotation(new ReflectionClass(ClassWithInvalidTypeAnnotation::class));
44
    }
45
46
    public function testLaxModeWithBadAnnotationAndStrictNamespace()
47
    {
48
        $annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::LAX_MODE, ['TheCodingMachine\\GraphQL\\Controllers\\Fixtures']);
49
50
        $this->expectException(AnnotationException::class);
51
        $annotationReader->getTypeAnnotation(new ReflectionClass(ClassWithInvalidClassAnnotation::class));
52
    }
53
54
    public function testGetAnnotationsStrictMode()
55
    {
56
        $annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::STRICT_MODE, []);
57
58
        $this->expectException(AnnotationException::class);
59
        $annotationReader->getClassAnnotations(new ReflectionClass(ClassWithInvalidClassAnnotation::class), Type::class);
60
    }
61
62
    public function testGetAnnotationsLaxModeWithBadAnnotation()
63
    {
64
        $annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::LAX_MODE, []);
65
66
        $types = $annotationReader->getClassAnnotations(new ReflectionClass(ClassWithInvalidClassAnnotation::class), Type::class);
67
        $this->assertSame([], $types);
68
    }
69
70
    public function testGetAnnotationsLaxModeWithSmellyAnnotation()
71
    {
72
        $annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::LAX_MODE, []);
73
74
        $this->expectException(AnnotationException::class);
75
        $annotationReader->getClassAnnotations(new ReflectionClass(ClassWithInvalidTypeAnnotation::class), Type::class);
76
    }
77
78
    public function testGetAnnotationsLaxModeWithBadAnnotationAndStrictNamespace()
79
    {
80
        $annotationReader = new AnnotationReader(new DoctrineAnnotationReader(), AnnotationReader::LAX_MODE, ['TheCodingMachine\\GraphQL\\Controllers\\Fixtures']);
81
82
        $this->expectException(AnnotationException::class);
83
        $annotationReader->getClassAnnotations(new ReflectionClass(ClassWithInvalidClassAnnotation::class), Type::class);
84
    }
85
86
87
}
88