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

NativeReaderTestCase::testUndefinedParameterMeta()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 10
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\Exception\SemanticAttributeException;
15
use Spiral\Attributes\Internal\Instantiator\Facade;
16
use Spiral\Attributes\Internal\NativeAttributeReader;
17
use Spiral\Attributes\ReaderInterface;
18
use Spiral\Tests\Attributes\Reader\Fixture\UndefinedMeta;
19
20
/**
21
 * @requires PHP >= 8.0
22
 *
23
 * @group unit
24
 * @group reader
25
 */
26
class NativeReaderTestCase extends ReaderTestCase
27
{
28
    protected function getReader(): ReaderInterface
29
    {
30
        return new NativeAttributeReader(new Facade());
31
    }
32
33
    public function testUndefinedClassMeta(): void
34
    {
35
        $this->expectException(SemanticAttributeException::class);
36
37
        $reader = $this->getReader();
38
39
        $this->iterableToArray(
40
            $reader->getClassMetadata(
41
                $this->getReflectionClass(UndefinedMeta::class)
42
            )
43
        );
44
    }
45
46
    public function testUndefinedConstantMeta(): void
47
    {
48
        $this->expectException(SemanticAttributeException::class);
49
        $reader = $this->getReader();
50
51
        $this->iterableToArray(
52
            $reader->getConstantMetadata(
53
                $this->getReflectionConstant(UndefinedMeta::class, 'CONSTANT')
54
            )
55
        );
56
    }
57
58
    public function testUndefinedPropertyMeta(): void
59
    {
60
        $this->expectException(SemanticAttributeException::class);
61
62
        $reader = $this->getReader();
63
64
        $this->iterableToArray(
65
            $reader->getPropertyMetadata(
66
                $this->getReflectionProperty(UndefinedMeta::class, 'property')
67
            )
68
        );
69
    }
70
71
    public function testUndefinedMethodMeta(): void
72
    {
73
        $this->expectException(SemanticAttributeException::class);
74
75
        $reader = $this->getReader();
76
77
        $this->iterableToArray(
78
            $reader->getFunctionMetadata(
79
                $this->getReflectionMethod(UndefinedMeta::class, 'method')
80
            )
81
        );
82
    }
83
84
    public function testUndefinedParameterMeta(): void
85
    {
86
        $this->expectException(SemanticAttributeException::class);
87
88
        $reader = $this->getReader();
89
90
        $this->iterableToArray(
91
            $reader->getParameterMetadata(
92
                $this->getReflectionMethodParameter(UndefinedMeta::class, 'method', 'parameter')
93
            )
94
        );
95
    }
96
97
    public function testUndefinedFunctionMeta(): void
98
    {
99
        $this->expectException(SemanticAttributeException::class);
100
101
        $reader = $this->getReader();
102
103
        $this->iterableToArray(
104
            $reader->getFunctionMetadata(
105
                $this->getReflectionFunction($this->fixture('undefined_meta'))
106
            )
107
        );
108
    }
109
}
110