Passed
Pull Request — master (#405)
by Kirill
08:21 queued 04:03
created

AttributeReaderTestCase   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 32
c 1
b 0
f 0
dl 0
loc 80
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testUndefinedPropertyMeta() 0 9 1
A testUndefinedParameterMeta() 0 9 1
A getReader() 0 3 1
A testUndefinedClassMeta() 0 9 1
A testUndefinedConstantMeta() 0 8 1
A testUndefinedMethodMeta() 0 9 1
A testUndefinedFunctionMeta() 0 9 1
1
<?php
2
3
/**
4
 * This file is part of Spiral Framework package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Attributes\Reader;
13
14
use Spiral\Attributes\AttributeReader;
15
use Spiral\Attributes\Exception\SemanticAttributeException;
16
use Spiral\Attributes\ReaderInterface;
17
use Spiral\Tests\Attributes\Reader\Fixture\UndefinedMeta;
18
19
/**
20
 * @group unit
21
 * @group reader
22
 */
23
class AttributeReaderTestCase extends ReaderTestCase
24
{
25
    protected function getReader(): ReaderInterface
26
    {
27
        return new AttributeReader();
28
    }
29
30
    public function testUndefinedClassMeta(): void
31
    {
32
        $this->expectException(SemanticAttributeException::class);
33
34
        $reader = $this->getReader();
35
36
        $this->iterableToArray(
37
            $reader->getClassMetadata(
38
                $this->getReflectionClass(UndefinedMeta::class)
39
            )
40
        );
41
    }
42
43
    public function testUndefinedConstantMeta(): void
44
    {
45
        $this->expectException(SemanticAttributeException::class);
46
        $reader = $this->getReader();
47
48
        $this->iterableToArray(
49
            $reader->getConstantMetadata(
50
                $this->getReflectionConstant(UndefinedMeta::class, 'CONSTANT')
51
            )
52
        );
53
    }
54
55
    public function testUndefinedPropertyMeta(): void
56
    {
57
        $this->expectException(SemanticAttributeException::class);
58
59
        $reader = $this->getReader();
60
61
        $this->iterableToArray(
62
            $reader->getPropertyMetadata(
63
                $this->getReflectionProperty(UndefinedMeta::class, 'property')
64
            )
65
        );
66
    }
67
68
    public function testUndefinedMethodMeta(): void
69
    {
70
        $this->expectException(SemanticAttributeException::class);
71
72
        $reader = $this->getReader();
73
74
        $this->iterableToArray(
75
            $reader->getFunctionMetadata(
76
                $this->getReflectionMethod(UndefinedMeta::class, 'method')
77
            )
78
        );
79
    }
80
81
    public function testUndefinedParameterMeta(): void
82
    {
83
        $this->expectException(SemanticAttributeException::class);
84
85
        $reader = $this->getReader();
86
87
        $this->iterableToArray(
88
            $reader->getParameterMetadata(
89
                $this->getReflectionMethodParameter(UndefinedMeta::class, 'method', 'parameter')
90
            )
91
        );
92
    }
93
94
    public function testUndefinedFunctionMeta(): void
95
    {
96
        $this->expectException(SemanticAttributeException::class);
97
98
        $reader = $this->getReader();
99
100
        $this->iterableToArray(
101
            $reader->getFunctionMetadata(
102
                $this->getReflectionFunction($this->fixture('undefined_meta'))
103
            )
104
        );
105
    }
106
}
107