10
10
namespace ZendTest \Code \Reflection ;
11
11
12
12
use PHPUnit \Framework \TestCase ;
13
+ use Zend \Code \Generator \DocBlock \Tag \VarTag ;
13
14
use Zend \Code \Reflection ;
14
15
15
16
/**
@@ -41,8 +42,16 @@ public function testTagShouldAllowMultipleWhitespacesBeforeDescription()
41
42
$ classReflection = new Reflection \ClassReflection (TestAsset \TestSampleClass6::class);
42
43
43
44
$ tag = $ classReflection ->getMethod ('doSomething ' )->getDocBlock ()->getTag ('descriptionTag ' );
44
- self ::assertNotEquals (' A tag with just a description ' , $ tag ->getContent (), 'Final Match Failed ' );
45
- self ::assertEquals ('A tag with just a description ' , $ tag ->getContent (), 'Final Match Failed ' );
45
+ self ::assertNotEquals (
46
+ ' A tag with just a description ' ,
47
+ $ tag ->getContent (),
48
+ 'Final Match Failed '
49
+ );
50
+ self ::assertEquals (
51
+ 'A tag with just a description ' ,
52
+ $ tag ->getContent (),
53
+ 'Final Match Failed '
54
+ );
46
55
}
47
56
48
57
public function testToString ()
@@ -53,7 +62,7 @@ public function testToString()
53
62
54
63
$ expectedString = 'DocBlock Tag [ * @descriptionTag ] ' . "\n" ;
55
64
56
- self ::assertEquals ($ expectedString , (string ) $ tag );
65
+ self ::assertEquals ($ expectedString , (string )$ tag );
57
66
}
58
67
59
68
public function testTypeParam ()
@@ -79,10 +88,13 @@ public function testAllowsMultipleSpacesInDocBlockTagLine()
79
88
80
89
$ paramTag = $ classReflection ->getMethod ('doSomething ' )->getDocBlock ()->getTag ('param ' );
81
90
82
-
83
91
self ::assertEquals ('int ' , $ paramTag ->getType (), 'Second Match Failed ' );
84
92
self ::assertEquals ('$var ' , $ paramTag ->getVariableName (), 'Third Match Failed ' );
85
- self ::assertEquals ('Description of $var ' , $ paramTag ->getDescription (), 'Final Match Failed ' );
93
+ self ::assertEquals (
94
+ 'Description of $var ' ,
95
+ $ paramTag ->getDescription (),
96
+ 'Final Match Failed '
97
+ );
86
98
}
87
99
88
100
/**
@@ -91,8 +103,7 @@ public function testAllowsMultipleSpacesInDocBlockTagLine()
91
103
public function testNamespaceInParam ()
92
104
{
93
105
$ classReflection = new Reflection \ClassReflection (TestAsset \TestSampleClass7::class);
94
- $ paramTag = $ classReflection ->getMethod ('doSomething ' )->getDocBlock ()->getTag ('param ' );
95
-
106
+ $ paramTag = $ classReflection ->getMethod ('doSomething ' )->getDocBlock ()->getTag ('param ' );
96
107
97
108
self ::assertEquals ('Zend\Foo\Bar ' , $ paramTag ->getType ());
98
109
self ::assertEquals ('$var ' , $ paramTag ->getVariableName ());
@@ -114,7 +125,11 @@ public function testAllowsMultipleSpacesInDocBlockTagLine2()
114
125
$ paramTag = $ classReflection ->getMethod ('doSomething ' )->getDocBlock ()->getTag ('return ' );
115
126
116
127
self ::assertEquals ('string ' , $ paramTag ->getType (), 'Second Match Failed ' );
117
- self ::assertEquals ('Description of return value ' , $ paramTag ->getDescription (), 'Final Match Failed ' );
128
+ self ::assertEquals (
129
+ 'Description of return value ' ,
130
+ $ paramTag ->getDescription (),
131
+ 'Final Match Failed '
132
+ );
118
133
}
119
134
120
135
/**
@@ -128,4 +143,48 @@ public function testReturnClassWithNamespace()
128
143
129
144
self ::assertEquals ('Zend\Code\Reflection\DocBlock ' , $ paramTag ->getType ());
130
145
}
146
+
147
+ /**
148
+ * @dataProvider propertyVarDocProvider
149
+ */
150
+ public function testPropertyVarDoc (
151
+ string $ property ,
152
+ array $ expectedTypes ,
153
+ ?string $ expectedName ,
154
+ ?string $ expectedDescription
155
+ ) {
156
+ $ classReflection = new Reflection \ClassReflection (
157
+ TestAsset \TestSampleClass14::class
158
+ );
159
+
160
+ /** @var VarTag $varTag */
161
+ $ varTag = $ classReflection
162
+ ->getProperty ($ property )
163
+ ->getDocBlock ()
164
+ ->getTag ('var ' );
165
+
166
+ self ::assertSame ($ expectedTypes , $ varTag ->getTypes ());
167
+ self ::assertSame ($ expectedName , $ varTag ->getVariableName ());
168
+ self ::assertSame ($ expectedDescription , $ varTag ->getDescription ());
169
+ }
170
+
171
+ public function propertyVarDocProvider (): array
172
+ {
173
+ return [
174
+ 'only type ' => ['onlyType ' , ['string ' ], null , null ],
175
+ 'type and description ' => [
176
+ 'typeDescription ' ,
177
+ ['string ' ],
178
+ null ,
179
+ 'Foo bar '
180
+ ],
181
+ 'type and name ' => ['typeName ' , ['string ' ], '$typeName ' , null ],
182
+ 'type, name and description ' => [
183
+ 'typeNameDescription ' ,
184
+ ['string ' ],
185
+ '$typeNameDescription ' ,
186
+ 'Foo bar '
187
+ ],
188
+ ];
189
+ }
131
190
}
0 commit comments