/
ClassAnnotationsTest.php
136 lines (125 loc) · 4.22 KB
/
ClassAnnotationsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php declare(strict_types=1);
namespace Lmc\Steward\Utils\Annotations;
use Lmc\Steward\Utils\Annotations\Fixtures\ClassEmptyDockBlock;
use Lmc\Steward\Utils\Annotations\Fixtures\ClassKeyAnnotations;
use Lmc\Steward\Utils\Annotations\Fixtures\ClassKeyValueAnnotations;
use Lmc\Steward\Utils\Annotations\Fixtures\ClassMixedAnnotations;
use Lmc\Steward\Utils\Annotations\Fixtures\ClassNoDocBlock;
use Lmc\Steward\Utils\Annotations\Fixtures\ClassWithMethods;
use PHPUnit\Framework\TestCase;
/**
* @covers \Lmc\Steward\Utils\Annotations\ClassAnnotations
*/
class ClassAnnotationsTest extends TestCase
{
/**
* @dataProvider provideClass
*/
public function testShouldGetAnnotationsForClass(string $className, array $expectedAnnotations): void
{
$annotations = ClassAnnotations::getAnnotationsForClass($className);
$this->assertSame($expectedAnnotations, $annotations);
}
/**
* @return array[]
*/
public function provideClass(): array
{
return [
'Class with empty doc block' => [
ClassEmptyDockBlock::class,
[],
],
'Class having no doc block at all' => [
ClassNoDocBlock::class,
[],
],
'Class with key-only annotations, without values' => [
ClassKeyAnnotations::class,
[
'first' => ['', ''],
'second' => [''],
'third' => [''],
],
],
'Class with key-value annotations' => [
ClassKeyValueAnnotations::class,
[
'first' => ['First value', 'Second value of first'],
'second' => ['Second value'],
'third' => ['Third "special" value'],
],
],
'Class with mixed key-only and key-value annotations' => [
ClassMixedAnnotations::class,
[
'first' => ['', 'First with some value'],
'second' => [''],
'third' => [''],
'fourth' => ['Fourth value'],
],
],
];
}
public function testShouldGetAnnotationsForInstances(): void
{
$annotations = ClassAnnotations::getAnnotationsForInstance(new ClassKeyAnnotations());
$this->assertSame(
[
'first' => ['', ''],
'second' => [''],
'third' => [''],
],
$annotations
);
}
/**
* @dataProvider provideMethod
*/
public function testShouldGetAnnotationsForMethodInClass(string $methodName, array $expectedAnnotations): void
{
$classInstance = new ClassWithMethods();
$annotations = ClassAnnotations::getAnnotationsForMethodOfInstance($classInstance, $methodName);
$this->assertSame($expectedAnnotations, $annotations);
}
/**
* @return array[]
*/
public function provideMethod(): array
{
return [
'Method with empty doc block' => [
'methodWithEmptyAnnotations',
[],
],
'Method having no doc block at all' => [
'methodWithout',
[],
],
'Method with key-only annotations, without values' => [
'methodWithKeys',
[
'first' => ['', ''],
'second' => [''],
'third' => [''],
],
],
'Method with key-value annotations' => [
'methodWithKeyValues',
[
'first' => ['First value', 'Second value of first'],
'second' => ['Second value'],
'third' => ['Third "special" @value!'],
],
],
'Method with mixed key-only and key-value annotations' => [
'methodWithMixedKeyValues',
[
'first' => ['', 'First with some value'],
'second' => ['Second with value', ''],
'third' => [''],
],
],
];
}
}