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

testFunctionParameterMetadataCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 4
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\Tests\Attributes\Concerns\InteractWithMetadata;
16
use Spiral\Tests\Attributes\Reader\Fixture\AnnotatedClass;
17
use Spiral\Tests\Attributes\Reader\Fixture\Annotation\ClassAnnotation;
18
use Spiral\Tests\Attributes\Reader\Fixture\Annotation\ConstantAnnotation;
19
use Spiral\Tests\Attributes\Reader\Fixture\Annotation\FunctionAnnotation;
20
use Spiral\Tests\Attributes\Reader\Fixture\Annotation\FunctionParameterAnnotation;
21
use Spiral\Tests\Attributes\Reader\Fixture\Annotation\MethodAnnotation;
22
use Spiral\Tests\Attributes\Reader\Fixture\Annotation\MethodParameterAnnotation;
23
use Spiral\Tests\Attributes\Reader\Fixture\Annotation\PropertyAnnotation;
24
use Spiral\Tests\Attributes\Reader\Fixture\UndefinedMeta;
25
use Spiral\Tests\Attributes\TestCase;
26
27
/**
28
 * @group unit
29
 * @group reader
30
 */
31
abstract class ReaderTestCase extends TestCase
32
{
33
    use InteractWithMetadata;
34
35
    /**
36
     * @var string
37
     */
38
    private const FIXTURE_FUNCTION_FQN = '\\Spiral\\Tests\\Attributes\\Reader\\Fixture\\annotated_function';
39
40
    /**
41
     * @var int
42
     */
43
    protected $classMetadataCount = 1;
44
45
    /**
46
     * @var int
47
     */
48
    protected $constantMetadataCount = 1;
49
50
    /**
51
     * @var int
52
     */
53
    protected $propertyMetadataCount = 1;
54
55
    /**
56
     * @var int
57
     */
58
    protected $methodMetadataCount = 1;
59
60
    /**
61
     * @var int
62
     */
63
    protected $methodParameterMetadataCount = 1;
64
65
    /**
66
     * @var int
67
     */
68
    protected $functionMetadataCount = 1;
69
70
    /**
71
     * @var int
72
     */
73
    protected $functionParameterMetadataCount = 1;
74
75
    public static function setUpBeforeClass(): void
76
    {
77
        parent::setUpBeforeClass();
78
79
        require_once __DIR__ . '/Fixture/function.php';
80
        require_once __DIR__ . '/Fixture/UndefinedMeta.php';
81
    }
82
83
    /**
84
     * @param string $suffix
85
     * @return string
86
     */
87
    protected function fixture(string $suffix): string
88
    {
89
        return '\\Spiral\\Tests\\Attributes\\Reader\\Fixture\\' . \trim($suffix, '\\');
90
    }
91
92
    public function testClassMetadataCount(): void
93
    {
94
        $this->assertCount($this->classMetadataCount,
95
            $this->getClassMetadata(AnnotatedClass::class)
96
        );
97
    }
98
99
    public function testClassMetadataObjects(): void
100
    {
101
        $expected = $this->newAnnotation(ClassAnnotation::class, [
102
            'field' => 'value'
103
        ]);
104
105
        if ($this->classMetadataCount === 0) {
106
            $this->expectNotToPerformAssertions();
107
        }
108
109
        foreach ($this->getClassMetadata(AnnotatedClass::class) as $actual) {
110
            $this->assertEquals($expected, $actual);
111
        }
112
    }
113
114
    public function testConstantMetadataCount(): void
115
    {
116
        $this->assertCount($this->constantMetadataCount,
117
            $this->getConstantMetadata(AnnotatedClass::class, 'CONSTANT')
118
        );
119
    }
120
121
    public function testConstantMetadataObjects(): void
122
    {
123
        $expected = $this->newAnnotation(ConstantAnnotation::class, [
124
            'field' => 'value'
125
        ]);
126
127
        if ($this->constantMetadataCount === 0) {
128
            $this->expectNotToPerformAssertions();
129
        }
130
131
        foreach ($this->getConstantMetadata(AnnotatedClass::class, 'CONSTANT') as $actual) {
132
            $this->assertEquals($expected, $actual);
133
        }
134
    }
135
136
    public function testPropertyMetadataCount(): void
137
    {
138
        $this->assertCount($this->propertyMetadataCount,
139
            $this->getPropertyMetadata(AnnotatedClass::class, 'property')
140
        );
141
    }
142
143
    public function testPropertyMetadataObjects(): void
144
    {
145
        $expected = $this->newAnnotation(PropertyAnnotation::class, [
146
            'field' => 'value'
147
        ]);
148
149
        if ($this->propertyMetadataCount === 0) {
150
            $this->expectNotToPerformAssertions();
151
        }
152
153
        foreach ($this->getPropertyMetadata(AnnotatedClass::class, 'property') as $actual) {
154
            $this->assertEquals($expected, $actual);
155
        }
156
    }
157
158
    public function testMethodMetadataCount(): void
159
    {
160
        $this->assertCount($this->methodMetadataCount,
161
            $this->getMethodMetadata(AnnotatedClass::class, 'method')
162
        );
163
    }
164
165
    public function testMethodMetadataObjects(): void
166
    {
167
        $expected = $this->newAnnotation(MethodAnnotation::class, [
168
            'field' => 'value'
169
        ]);
170
171
        if ($this->methodMetadataCount === 0) {
172
            $this->expectNotToPerformAssertions();
173
        }
174
175
        foreach ($this->getMethodMetadata(AnnotatedClass::class, 'method') as $actual) {
176
            $this->assertEquals($expected, $actual);
177
        }
178
    }
179
180
    public function testMethodParameterMetadataCount(): void
181
    {
182
        $this->assertCount($this->methodParameterMetadataCount,
183
            $this->getMethodParameterMetadata(AnnotatedClass::class, 'method', 'parameter')
184
        );
185
    }
186
187
    public function testMethodParameterMetadataObjects(): void
188
    {
189
        $expected = $this->newAnnotation(MethodParameterAnnotation::class, [
190
            'field' => 'value'
191
        ]);
192
193
        if ($this->methodParameterMetadataCount === 0) {
194
            $this->expectNotToPerformAssertions();
195
        }
196
197
        foreach ($this->getMethodParameterMetadata(AnnotatedClass::class, 'method', 'parameter') as $actual) {
198
            $this->assertEquals($expected, $actual);
199
        }
200
    }
201
202
    public function testFunctionMetadataCount(): void
203
    {
204
        $this->assertCount($this->functionMetadataCount,
205
            $this->getFunctionMetadata($this->fixture('annotated_function'))
206
        );
207
    }
208
209
    public function testFunctionMetadataObjects(): void
210
    {
211
        $expected = $this->newAnnotation(FunctionAnnotation::class, [
212
            'field' => 'value'
213
        ]);
214
215
        if ($this->functionMetadataCount === 0) {
216
            $this->expectNotToPerformAssertions();
217
        }
218
219
        foreach ($this->getFunctionMetadata($this->fixture('annotated_function')) as $actual) {
220
            $this->assertEquals($expected, $actual);
221
        }
222
    }
223
224
    public function testFunctionParameterMetadataCount(): void
225
    {
226
        $this->assertCount($this->functionParameterMetadataCount,
227
            $this->getFunctionParameterMetadata($this->fixture('annotated_function'), 'parameter')
228
        );
229
    }
230
231
    public function testFunctionParameterMetadataObjects(): void
232
    {
233
        $expected = $this->newAnnotation(FunctionParameterAnnotation::class, [
234
            'field' => 'value'
235
        ]);
236
237
        if ($this->functionParameterMetadataCount === 0) {
238
            $this->expectNotToPerformAssertions();
239
        }
240
241
        $function = $this->fixture('annotated_function');
242
        foreach ($this->getFunctionParameterMetadata($function, 'parameter') as $actual) {
243
            $this->assertEquals($expected, $actual);
244
        }
245
    }
246
}
247