@@ -19,14 +19,15 @@ final class BackfillReadonlyTest extends AbstractMethodUnitTest
1919 * Test that the "readonly" keyword is tokenized as such.
2020 *
2121 * @param string $testMarker The comment which prefaces the target token in the test file.
22- * @param string $testContent The token content to look for.
22+ * @param string $testContent Optional. The token content to look for.
23+ * Defaults to lowercase "readonly".
2324 *
2425 * @dataProvider dataReadonly
2526 * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
2627 *
2728 * @return void
2829 */
29- public function testReadonly ($ testMarker , $ testContent )
30+ public function testReadonly ($ testMarker , $ testContent= ' readonly ' )
3031 {
3132 $ tokens = self ::$ phpcsFile ->getTokens ();
3233
@@ -42,150 +43,117 @@ public function testReadonly($testMarker, $testContent)
4243 *
4344 * @see testReadonly()
4445 *
45- * @return array
46+ * @return array<string, array<string, string>>
4647 */
4748 public static function dataReadonly ()
4849 {
4950 return [
50- [
51- '/* testReadonlyProperty */ ' ,
52- 'readonly ' ,
51+ 'property declaration, no visibility ' => [
52+ 'testMarker ' => '/* testReadonlyProperty */ ' ,
5353 ],
54- [
55- '/* testVarReadonlyProperty */ ' ,
56- 'readonly ' ,
54+ 'property declaration, var keyword before ' => [
55+ 'testMarker ' => '/* testVarReadonlyProperty */ ' ,
5756 ],
58- [
59- '/* testReadonlyVarProperty */ ' ,
60- 'readonly ' ,
57+ 'property declaration, var keyword after ' => [
58+ 'testMarker ' => '/* testReadonlyVarProperty */ ' ,
6159 ],
62- [
63- '/* testStaticReadonlyProperty */ ' ,
64- 'readonly ' ,
60+ 'property declaration, static before ' => [
61+ 'testMarker ' => '/* testStaticReadonlyProperty */ ' ,
6562 ],
66- [
67- '/* testReadonlyStaticProperty */ ' ,
68- 'readonly ' ,
63+ 'property declaration, static after ' => [
64+ 'testMarker ' => '/* testReadonlyStaticProperty */ ' ,
6965 ],
70- [
71- '/* testConstReadonlyProperty */ ' ,
72- 'readonly ' ,
66+ 'constant declaration, with visibility ' => [
67+ 'testMarker ' => '/* testConstReadonlyProperty */ ' ,
7368 ],
74- [
75- '/* testReadonlyPropertyWithoutType */ ' ,
76- 'readonly ' ,
69+ 'property declaration, missing type ' => [
70+ 'testMarker ' => '/* testReadonlyPropertyWithoutType */ ' ,
7771 ],
78- [
79- '/* testPublicReadonlyProperty */ ' ,
80- 'readonly ' ,
72+ 'property declaration, public before ' => [
73+ 'testMarker ' => '/* testPublicReadonlyProperty */ ' ,
8174 ],
82- [
83- '/* testProtectedReadonlyProperty */ ' ,
84- 'readonly ' ,
75+ 'property declaration, protected before ' => [
76+ 'testMarker ' => '/* testProtectedReadonlyProperty */ ' ,
8577 ],
86- [
87- '/* testPrivateReadonlyProperty */ ' ,
88- 'readonly ' ,
78+ 'property declaration, private before ' => [
79+ 'testMarker ' => '/* testPrivateReadonlyProperty */ ' ,
8980 ],
90- [
91- '/* testPublicReadonlyPropertyWithReadonlyFirst */ ' ,
92- 'readonly ' ,
81+ 'property declaration, public after ' => [
82+ 'testMarker ' => '/* testPublicReadonlyPropertyWithReadonlyFirst */ ' ,
9383 ],
94- [
95- '/* testProtectedReadonlyPropertyWithReadonlyFirst */ ' ,
96- 'readonly ' ,
84+ 'property declaration, protected after ' => [
85+ 'testMarker ' => '/* testProtectedReadonlyPropertyWithReadonlyFirst */ ' ,
9786 ],
98- [
99- '/* testPrivateReadonlyPropertyWithReadonlyFirst */ ' ,
100- 'readonly ' ,
87+ 'property declaration, private after ' => [
88+ 'testMarker ' => '/* testPrivateReadonlyPropertyWithReadonlyFirst */ ' ,
10189 ],
102- [
103- '/* testReadonlyWithCommentsInDeclaration */ ' ,
104- 'readonly ' ,
90+ 'property declaration, private before, comments in declaration ' => [
91+ 'testMarker ' => '/* testReadonlyWithCommentsInDeclaration */ ' ,
10592 ],
106- [
107- '/* testReadonlyWithNullableProperty */ ' ,
108- 'readonly ' ,
93+ 'property declaration, private before, nullable type ' => [
94+ 'testMarker ' => '/* testReadonlyWithNullableProperty */ ' ,
10995 ],
110- [
111- '/* testReadonlyNullablePropertyWithUnionTypeHintAndNullFirst */ ' ,
112- 'readonly ' ,
96+ 'property declaration, private before, union type, null first ' => [
97+ 'testMarker ' => '/* testReadonlyNullablePropertyWithUnionTypeHintAndNullFirst */ ' ,
11398 ],
114- [
115- '/* testReadonlyNullablePropertyWithUnionTypeHintAndNullLast */ ' ,
116- 'readonly ' ,
99+ 'property declaration, private before, union type, null last ' => [
100+ 'testMarker ' => '/* testReadonlyNullablePropertyWithUnionTypeHintAndNullLast */ ' ,
117101 ],
118- [
119- '/* testReadonlyPropertyWithArrayTypeHint */ ' ,
120- 'readonly ' ,
102+ 'property declaration, private before, array type ' => [
103+ 'testMarker ' => '/* testReadonlyPropertyWithArrayTypeHint */ ' ,
121104 ],
122- [
123- '/* testReadonlyPropertyWithSelfTypeHint */ ' ,
124- 'readonly ' ,
105+ 'property declaration, private before, self type ' => [
106+ 'testMarker ' => '/* testReadonlyPropertyWithSelfTypeHint */ ' ,
125107 ],
126- [
127- '/* testReadonlyPropertyWithParentTypeHint */ ' ,
128- 'readonly ' ,
108+ 'property declaration, private before, parent type ' => [
109+ 'testMarker ' => '/* testReadonlyPropertyWithParentTypeHint */ ' ,
129110 ],
130- [
131- '/* testReadonlyPropertyWithFullyQualifiedTypeHint */ ' ,
132- 'readonly ' ,
111+ 'property declaration, private before, FQN type ' => [
112+ 'testMarker ' => '/* testReadonlyPropertyWithFullyQualifiedTypeHint */ ' ,
133113 ],
134- [
135- '/* testReadonlyIsCaseInsensitive */ ' ,
136- 'ReAdOnLy ' ,
114+ ' property declaration, public before, mixed case ' => [
115+ 'testMarker ' => ' /* testReadonlyIsCaseInsensitive */ ' ,
116+ 'testContent ' => ' ReAdOnLy ' ,
137117 ],
138- [
139- '/* testReadonlyConstructorPropertyPromotion */ ' ,
140- 'readonly ' ,
118+ 'property declaration, constructor property promotion ' => [
119+ 'testMarker ' => '/* testReadonlyConstructorPropertyPromotion */ ' ,
141120 ],
142- [
143- '/* testReadonlyConstructorPropertyPromotionWithReference */ ' ,
144- 'ReadOnly ' ,
121+ ' property declaration, constructor property promotion with reference, mixed case ' => [
122+ 'testMarker ' => ' /* testReadonlyConstructorPropertyPromotionWithReference */ ' ,
123+ 'testContent ' => ' ReadOnly ' ,
145124 ],
146- [
147- '/* testReadonlyPropertyInAnonymousClass */ ' ,
148- 'readonly ' ,
125+ 'property declaration, in anonymous class ' => [
126+ 'testMarker ' => '/* testReadonlyPropertyInAnonymousClass */ ' ,
149127 ],
150- [
151- '/* testReadonlyPropertyDNFTypeUnqualified */ ' ,
152- 'readonly ' ,
128+ 'property declaration, no visibility, DNF type, unqualified ' => [
129+ 'testMarker ' => '/* testReadonlyPropertyDNFTypeUnqualified */ ' ,
153130 ],
154- [
155- '/* testReadonlyPropertyDNFTypeFullyQualified */ ' ,
156- 'readonly ' ,
131+ 'property declaration, public before, DNF type, fully qualified ' => [
132+ 'testMarker ' => '/* testReadonlyPropertyDNFTypeFullyQualified */ ' ,
157133 ],
158- [
159- '/* testReadonlyPropertyDNFTypePartiallyQualified */ ' ,
160- 'readonly ' ,
134+ 'property declaration, protected before, DNF type, partially qualified ' => [
135+ 'testMarker ' => '/* testReadonlyPropertyDNFTypePartiallyQualified */ ' ,
161136 ],
162- [
163- '/* testReadonlyPropertyDNFTypeRelativeName */ ' ,
164- 'readonly ' ,
137+ 'property declaration, private before, DNF type, namespace relative name ' => [
138+ 'testMarker ' => '/* testReadonlyPropertyDNFTypeRelativeName */ ' ,
165139 ],
166- [
167- '/* testReadonlyPropertyDNFTypeMultipleSets */ ' ,
168- 'readonly ' ,
140+ 'property declaration, private before, DNF type, multiple sets ' => [
141+ 'testMarker ' => '/* testReadonlyPropertyDNFTypeMultipleSets */ ' ,
169142 ],
170- [
171- '/* testReadonlyPropertyDNFTypeWithArray */ ' ,
172- 'readonly ' ,
143+ 'property declaration, private before, DNF type, union with array ' => [
144+ 'testMarker ' => '/* testReadonlyPropertyDNFTypeWithArray */ ' ,
173145 ],
174- [
175- '/* testReadonlyPropertyDNFTypeWithSpacesAndComments */ ' ,
176- 'readonly ' ,
146+ 'property declaration, private before, DNF type, with spaces and comment ' => [
147+ 'testMarker ' => '/* testReadonlyPropertyDNFTypeWithSpacesAndComments */ ' ,
177148 ],
178- [
179- '/* testReadonlyConstructorPropertyPromotionWithDNF */ ' ,
180- 'readonly ' ,
149+ 'property declaration, constructor property promotion, DNF type ' => [
150+ 'testMarker ' => '/* testReadonlyConstructorPropertyPromotionWithDNF */ ' ,
181151 ],
182- [
183- '/* testReadonlyConstructorPropertyPromotionWithDNFAndRefence */ ' ,
184- 'readonly ' ,
152+ 'property declaration, constructor property promotion, DNF type and reference ' => [
153+ 'testMarker ' => '/* testReadonlyConstructorPropertyPromotionWithDNFAndReference */ ' ,
185154 ],
186- [
187- '/* testParseErrorLiveCoding */ ' ,
188- 'readonly ' ,
155+ 'live coding / parse error ' => [
156+ 'testMarker ' => '/* testParseErrorLiveCoding */ ' ,
189157 ],
190158 ];
191159
@@ -196,14 +164,15 @@ public static function dataReadonly()
196164 * Test that "readonly" when not used as the keyword is still tokenized as `T_STRING`.
197165 *
198166 * @param string $testMarker The comment which prefaces the target token in the test file.
199- * @param string $testContent The token content to look for.
167+ * @param string $testContent Optional. The token content to look for.
168+ * Defaults to lowercase "readonly".
200169 *
201170 * @dataProvider dataNotReadonly
202171 * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
203172 *
204173 * @return void
205174 */
206- public function testNotReadonly ($ testMarker , $ testContent )
175+ public function testNotReadonly ($ testMarker , $ testContent= ' readonly ' )
207176 {
208177 $ tokens = self ::$ phpcsFile ->getTokens ();
209178
@@ -219,78 +188,67 @@ public function testNotReadonly($testMarker, $testContent)
219188 *
220189 * @see testNotReadonly()
221190 *
222- * @return array
191+ * @return array<string, array<string, string>>
223192 */
224193 public static function dataNotReadonly ()
225194 {
226195 return [
227- [
228- '/* testReadonlyUsedAsClassConstantName */ ' ,
229- 'READONLY ' ,
196+ ' name of a constant, context: declaration using "const" keyword, uppercase ' => [
197+ 'testMarker ' => ' /* testReadonlyUsedAsClassConstantName */ ' ,
198+ 'testContent ' => ' READONLY ' ,
230199 ],
231- [
232- '/* testReadonlyUsedAsMethodName */ ' ,
233- 'readonly ' ,
200+ 'name of a method, context: declaration ' => [
201+ 'testMarker ' => '/* testReadonlyUsedAsMethodName */ ' ,
234202 ],
235- [
236- '/* testReadonlyUsedAsPropertyName */ ' ,
237- 'readonly ' ,
203+ 'name of a property, context: property access ' => [
204+ 'testMarker ' => '/* testReadonlyUsedAsPropertyName */ ' ,
238205 ],
239- [
240- '/* testReadonlyPropertyInTernaryOperator */ ' ,
241- 'readonly ' ,
206+ 'name of a property, context: property access in ternary ' => [
207+ 'testMarker ' => '/* testReadonlyPropertyInTernaryOperator */ ' ,
242208 ],
243- [
244- '/* testReadonlyUsedAsFunctionName */ ' ,
245- 'readonly ' ,
209+ 'name of a function, context: declaration ' => [
210+ 'testMarker ' => '/* testReadonlyUsedAsFunctionName */ ' ,
246211 ],
247- [
248- '/* testReadonlyUsedAsFunctionNameWithReturnByRef */ ' ,
249- 'readonly ' ,
212+ 'name of a function, context: declaration with return by ref ' => [
213+ 'testMarker ' => '/* testReadonlyUsedAsFunctionNameWithReturnByRef */ ' ,
250214 ],
251- [
252- '/* testReadonlyUsedAsNamespaceName */ ' ,
253- 'Readonly ' ,
215+ ' name of namespace, context: declaration, mixed case ' => [
216+ 'testMarker ' => ' /* testReadonlyUsedAsNamespaceName */ ' ,
217+ 'testContent ' => ' Readonly ' ,
254218 ],
255- [
256- '/* testReadonlyUsedAsPartOfNamespaceName */ ' ,
257- 'Readonly ' ,
219+ ' partial name of namespace, context: declaration, mixed case ' => [
220+ 'testMarker ' => ' /* testReadonlyUsedAsPartOfNamespaceName */ ' ,
221+ 'testContent ' => ' Readonly ' ,
258222 ],
259- [
260- '/* testReadonlyAsFunctionCall */ ' ,
261- 'readonly ' ,
223+ 'name of a function, context: call ' => [
224+ 'testMarker ' => '/* testReadonlyAsFunctionCall */ ' ,
262225 ],
263- [
264- '/* testReadonlyAsNamespacedFunctionCall */ ' ,
265- 'readonly ' ,
226+ 'name of a namespaced function, context: partially qualified call ' => [
227+ 'testMarker ' => '/* testReadonlyAsNamespacedFunctionCall */ ' ,
266228 ],
267- [
268- '/* testReadonlyAsNamespaceRelativeFunctionCall */ ' ,
269- 'ReadOnly ' ,
229+ ' name of a function, context: namespace relative call, mixed case ' => [
230+ 'testMarker ' => ' /* testReadonlyAsNamespaceRelativeFunctionCall */ ' ,
231+ 'testContent ' => ' ReadOnly ' ,
270232 ],
271- [
272- '/* testReadonlyAsMethodCall */ ' ,
273- 'readonly ' ,
233+ 'name of a method, context: method call on object ' => [
234+ 'testMarker ' => '/* testReadonlyAsMethodCall */ ' ,
274235 ],
275- [
276- '/* testReadonlyAsNullsafeMethodCall */ ' ,
277- 'readOnly ' ,
236+ ' name of a method, context: nullsafe method call on object ' => [
237+ 'testMarker ' => ' /* testReadonlyAsNullsafeMethodCall */ ' ,
238+ 'testContent ' => ' readOnly ' ,
278239 ],
279- [
280- '/* testReadonlyAsStaticMethodCallWithSpace */ ' ,
281- 'readonly ' ,
240+ 'name of a method, context: static method call with space after ' => [
241+ 'testMarker ' => '/* testReadonlyAsStaticMethodCallWithSpace */ ' ,
282242 ],
283- [
284- '/* testClassConstantFetchWithReadonlyAsConstantName */ ' ,
285- 'READONLY ' ,
243+ ' name of a constant, context: constant access - uppercase ' => [
244+ 'testMarker ' => ' /* testClassConstantFetchWithReadonlyAsConstantName */ ' ,
245+ 'testContent ' => ' READONLY ' ,
286246 ],
287- [
288- '/* testReadonlyUsedAsFunctionCallWithSpaceBetweenKeywordAndParens */ ' ,
289- 'readonly ' ,
247+ 'name of a function, context: call with space and comment between keyword and parens ' => [
248+ 'testMarker ' => '/* testReadonlyUsedAsFunctionCallWithSpaceBetweenKeywordAndParens */ ' ,
290249 ],
291- [
292- '/* testReadonlyUsedAsMethodNameWithDNFParam */ ' ,
293- 'readonly ' ,
250+ 'name of a method, context: declaration with DNF parameter ' => [
251+ 'testMarker ' => '/* testReadonlyUsedAsMethodNameWithDNFParam */ ' ,
294252 ],
295253 ];
296254
0 commit comments