@@ -19,14 +19,15 @@ final class BackfillReadonlyTest extends AbstractMethodUnitTest
19
19
* Test that the "readonly" keyword is tokenized as such.
20
20
*
21
21
* @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".
23
24
*
24
25
* @dataProvider dataReadonly
25
26
* @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
26
27
*
27
28
* @return void
28
29
*/
29
- public function testReadonly ($ testMarker , $ testContent )
30
+ public function testReadonly ($ testMarker , $ testContent= ' readonly ' )
30
31
{
31
32
$ tokens = self ::$ phpcsFile ->getTokens ();
32
33
@@ -42,150 +43,117 @@ public function testReadonly($testMarker, $testContent)
42
43
*
43
44
* @see testReadonly()
44
45
*
45
- * @return array
46
+ * @return array<string, array<string, string>>
46
47
*/
47
48
public static function dataReadonly ()
48
49
{
49
50
return [
50
- [
51
- '/* testReadonlyProperty */ ' ,
52
- 'readonly ' ,
51
+ 'property declaration, no visibility ' => [
52
+ 'testMarker ' => '/* testReadonlyProperty */ ' ,
53
53
],
54
- [
55
- '/* testVarReadonlyProperty */ ' ,
56
- 'readonly ' ,
54
+ 'property declaration, var keyword before ' => [
55
+ 'testMarker ' => '/* testVarReadonlyProperty */ ' ,
57
56
],
58
- [
59
- '/* testReadonlyVarProperty */ ' ,
60
- 'readonly ' ,
57
+ 'property declaration, var keyword after ' => [
58
+ 'testMarker ' => '/* testReadonlyVarProperty */ ' ,
61
59
],
62
- [
63
- '/* testStaticReadonlyProperty */ ' ,
64
- 'readonly ' ,
60
+ 'property declaration, static before ' => [
61
+ 'testMarker ' => '/* testStaticReadonlyProperty */ ' ,
65
62
],
66
- [
67
- '/* testReadonlyStaticProperty */ ' ,
68
- 'readonly ' ,
63
+ 'property declaration, static after ' => [
64
+ 'testMarker ' => '/* testReadonlyStaticProperty */ ' ,
69
65
],
70
- [
71
- '/* testConstReadonlyProperty */ ' ,
72
- 'readonly ' ,
66
+ 'constant declaration, with visibility ' => [
67
+ 'testMarker ' => '/* testConstReadonlyProperty */ ' ,
73
68
],
74
- [
75
- '/* testReadonlyPropertyWithoutType */ ' ,
76
- 'readonly ' ,
69
+ 'property declaration, missing type ' => [
70
+ 'testMarker ' => '/* testReadonlyPropertyWithoutType */ ' ,
77
71
],
78
- [
79
- '/* testPublicReadonlyProperty */ ' ,
80
- 'readonly ' ,
72
+ 'property declaration, public before ' => [
73
+ 'testMarker ' => '/* testPublicReadonlyProperty */ ' ,
81
74
],
82
- [
83
- '/* testProtectedReadonlyProperty */ ' ,
84
- 'readonly ' ,
75
+ 'property declaration, protected before ' => [
76
+ 'testMarker ' => '/* testProtectedReadonlyProperty */ ' ,
85
77
],
86
- [
87
- '/* testPrivateReadonlyProperty */ ' ,
88
- 'readonly ' ,
78
+ 'property declaration, private before ' => [
79
+ 'testMarker ' => '/* testPrivateReadonlyProperty */ ' ,
89
80
],
90
- [
91
- '/* testPublicReadonlyPropertyWithReadonlyFirst */ ' ,
92
- 'readonly ' ,
81
+ 'property declaration, public after ' => [
82
+ 'testMarker ' => '/* testPublicReadonlyPropertyWithReadonlyFirst */ ' ,
93
83
],
94
- [
95
- '/* testProtectedReadonlyPropertyWithReadonlyFirst */ ' ,
96
- 'readonly ' ,
84
+ 'property declaration, protected after ' => [
85
+ 'testMarker ' => '/* testProtectedReadonlyPropertyWithReadonlyFirst */ ' ,
97
86
],
98
- [
99
- '/* testPrivateReadonlyPropertyWithReadonlyFirst */ ' ,
100
- 'readonly ' ,
87
+ 'property declaration, private after ' => [
88
+ 'testMarker ' => '/* testPrivateReadonlyPropertyWithReadonlyFirst */ ' ,
101
89
],
102
- [
103
- '/* testReadonlyWithCommentsInDeclaration */ ' ,
104
- 'readonly ' ,
90
+ 'property declaration, private before, comments in declaration ' => [
91
+ 'testMarker ' => '/* testReadonlyWithCommentsInDeclaration */ ' ,
105
92
],
106
- [
107
- '/* testReadonlyWithNullableProperty */ ' ,
108
- 'readonly ' ,
93
+ 'property declaration, private before, nullable type ' => [
94
+ 'testMarker ' => '/* testReadonlyWithNullableProperty */ ' ,
109
95
],
110
- [
111
- '/* testReadonlyNullablePropertyWithUnionTypeHintAndNullFirst */ ' ,
112
- 'readonly ' ,
96
+ 'property declaration, private before, union type, null first ' => [
97
+ 'testMarker ' => '/* testReadonlyNullablePropertyWithUnionTypeHintAndNullFirst */ ' ,
113
98
],
114
- [
115
- '/* testReadonlyNullablePropertyWithUnionTypeHintAndNullLast */ ' ,
116
- 'readonly ' ,
99
+ 'property declaration, private before, union type, null last ' => [
100
+ 'testMarker ' => '/* testReadonlyNullablePropertyWithUnionTypeHintAndNullLast */ ' ,
117
101
],
118
- [
119
- '/* testReadonlyPropertyWithArrayTypeHint */ ' ,
120
- 'readonly ' ,
102
+ 'property declaration, private before, array type ' => [
103
+ 'testMarker ' => '/* testReadonlyPropertyWithArrayTypeHint */ ' ,
121
104
],
122
- [
123
- '/* testReadonlyPropertyWithSelfTypeHint */ ' ,
124
- 'readonly ' ,
105
+ 'property declaration, private before, self type ' => [
106
+ 'testMarker ' => '/* testReadonlyPropertyWithSelfTypeHint */ ' ,
125
107
],
126
- [
127
- '/* testReadonlyPropertyWithParentTypeHint */ ' ,
128
- 'readonly ' ,
108
+ 'property declaration, private before, parent type ' => [
109
+ 'testMarker ' => '/* testReadonlyPropertyWithParentTypeHint */ ' ,
129
110
],
130
- [
131
- '/* testReadonlyPropertyWithFullyQualifiedTypeHint */ ' ,
132
- 'readonly ' ,
111
+ 'property declaration, private before, FQN type ' => [
112
+ 'testMarker ' => '/* testReadonlyPropertyWithFullyQualifiedTypeHint */ ' ,
133
113
],
134
- [
135
- '/* testReadonlyIsCaseInsensitive */ ' ,
136
- 'ReAdOnLy ' ,
114
+ ' property declaration, public before, mixed case ' => [
115
+ 'testMarker ' => ' /* testReadonlyIsCaseInsensitive */ ' ,
116
+ 'testContent ' => ' ReAdOnLy ' ,
137
117
],
138
- [
139
- '/* testReadonlyConstructorPropertyPromotion */ ' ,
140
- 'readonly ' ,
118
+ 'property declaration, constructor property promotion ' => [
119
+ 'testMarker ' => '/* testReadonlyConstructorPropertyPromotion */ ' ,
141
120
],
142
- [
143
- '/* testReadonlyConstructorPropertyPromotionWithReference */ ' ,
144
- 'ReadOnly ' ,
121
+ ' property declaration, constructor property promotion with reference, mixed case ' => [
122
+ 'testMarker ' => ' /* testReadonlyConstructorPropertyPromotionWithReference */ ' ,
123
+ 'testContent ' => ' ReadOnly ' ,
145
124
],
146
- [
147
- '/* testReadonlyPropertyInAnonymousClass */ ' ,
148
- 'readonly ' ,
125
+ 'property declaration, in anonymous class ' => [
126
+ 'testMarker ' => '/* testReadonlyPropertyInAnonymousClass */ ' ,
149
127
],
150
- [
151
- '/* testReadonlyPropertyDNFTypeUnqualified */ ' ,
152
- 'readonly ' ,
128
+ 'property declaration, no visibility, DNF type, unqualified ' => [
129
+ 'testMarker ' => '/* testReadonlyPropertyDNFTypeUnqualified */ ' ,
153
130
],
154
- [
155
- '/* testReadonlyPropertyDNFTypeFullyQualified */ ' ,
156
- 'readonly ' ,
131
+ 'property declaration, public before, DNF type, fully qualified ' => [
132
+ 'testMarker ' => '/* testReadonlyPropertyDNFTypeFullyQualified */ ' ,
157
133
],
158
- [
159
- '/* testReadonlyPropertyDNFTypePartiallyQualified */ ' ,
160
- 'readonly ' ,
134
+ 'property declaration, protected before, DNF type, partially qualified ' => [
135
+ 'testMarker ' => '/* testReadonlyPropertyDNFTypePartiallyQualified */ ' ,
161
136
],
162
- [
163
- '/* testReadonlyPropertyDNFTypeRelativeName */ ' ,
164
- 'readonly ' ,
137
+ 'property declaration, private before, DNF type, namespace relative name ' => [
138
+ 'testMarker ' => '/* testReadonlyPropertyDNFTypeRelativeName */ ' ,
165
139
],
166
- [
167
- '/* testReadonlyPropertyDNFTypeMultipleSets */ ' ,
168
- 'readonly ' ,
140
+ 'property declaration, private before, DNF type, multiple sets ' => [
141
+ 'testMarker ' => '/* testReadonlyPropertyDNFTypeMultipleSets */ ' ,
169
142
],
170
- [
171
- '/* testReadonlyPropertyDNFTypeWithArray */ ' ,
172
- 'readonly ' ,
143
+ 'property declaration, private before, DNF type, union with array ' => [
144
+ 'testMarker ' => '/* testReadonlyPropertyDNFTypeWithArray */ ' ,
173
145
],
174
- [
175
- '/* testReadonlyPropertyDNFTypeWithSpacesAndComments */ ' ,
176
- 'readonly ' ,
146
+ 'property declaration, private before, DNF type, with spaces and comment ' => [
147
+ 'testMarker ' => '/* testReadonlyPropertyDNFTypeWithSpacesAndComments */ ' ,
177
148
],
178
- [
179
- '/* testReadonlyConstructorPropertyPromotionWithDNF */ ' ,
180
- 'readonly ' ,
149
+ 'property declaration, constructor property promotion, DNF type ' => [
150
+ 'testMarker ' => '/* testReadonlyConstructorPropertyPromotionWithDNF */ ' ,
181
151
],
182
- [
183
- '/* testReadonlyConstructorPropertyPromotionWithDNFAndRefence */ ' ,
184
- 'readonly ' ,
152
+ 'property declaration, constructor property promotion, DNF type and reference ' => [
153
+ 'testMarker ' => '/* testReadonlyConstructorPropertyPromotionWithDNFAndReference */ ' ,
185
154
],
186
- [
187
- '/* testParseErrorLiveCoding */ ' ,
188
- 'readonly ' ,
155
+ 'live coding / parse error ' => [
156
+ 'testMarker ' => '/* testParseErrorLiveCoding */ ' ,
189
157
],
190
158
];
191
159
@@ -196,14 +164,15 @@ public static function dataReadonly()
196
164
* Test that "readonly" when not used as the keyword is still tokenized as `T_STRING`.
197
165
*
198
166
* @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".
200
169
*
201
170
* @dataProvider dataNotReadonly
202
171
* @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
203
172
*
204
173
* @return void
205
174
*/
206
- public function testNotReadonly ($ testMarker , $ testContent )
175
+ public function testNotReadonly ($ testMarker , $ testContent= ' readonly ' )
207
176
{
208
177
$ tokens = self ::$ phpcsFile ->getTokens ();
209
178
@@ -219,78 +188,67 @@ public function testNotReadonly($testMarker, $testContent)
219
188
*
220
189
* @see testNotReadonly()
221
190
*
222
- * @return array
191
+ * @return array<string, array<string, string>>
223
192
*/
224
193
public static function dataNotReadonly ()
225
194
{
226
195
return [
227
- [
228
- '/* testReadonlyUsedAsClassConstantName */ ' ,
229
- 'READONLY ' ,
196
+ ' name of a constant, context: declaration using "const" keyword, uppercase ' => [
197
+ 'testMarker ' => ' /* testReadonlyUsedAsClassConstantName */ ' ,
198
+ 'testContent ' => ' READONLY ' ,
230
199
],
231
- [
232
- '/* testReadonlyUsedAsMethodName */ ' ,
233
- 'readonly ' ,
200
+ 'name of a method, context: declaration ' => [
201
+ 'testMarker ' => '/* testReadonlyUsedAsMethodName */ ' ,
234
202
],
235
- [
236
- '/* testReadonlyUsedAsPropertyName */ ' ,
237
- 'readonly ' ,
203
+ 'name of a property, context: property access ' => [
204
+ 'testMarker ' => '/* testReadonlyUsedAsPropertyName */ ' ,
238
205
],
239
- [
240
- '/* testReadonlyPropertyInTernaryOperator */ ' ,
241
- 'readonly ' ,
206
+ 'name of a property, context: property access in ternary ' => [
207
+ 'testMarker ' => '/* testReadonlyPropertyInTernaryOperator */ ' ,
242
208
],
243
- [
244
- '/* testReadonlyUsedAsFunctionName */ ' ,
245
- 'readonly ' ,
209
+ 'name of a function, context: declaration ' => [
210
+ 'testMarker ' => '/* testReadonlyUsedAsFunctionName */ ' ,
246
211
],
247
- [
248
- '/* testReadonlyUsedAsFunctionNameWithReturnByRef */ ' ,
249
- 'readonly ' ,
212
+ 'name of a function, context: declaration with return by ref ' => [
213
+ 'testMarker ' => '/* testReadonlyUsedAsFunctionNameWithReturnByRef */ ' ,
250
214
],
251
- [
252
- '/* testReadonlyUsedAsNamespaceName */ ' ,
253
- 'Readonly ' ,
215
+ ' name of namespace, context: declaration, mixed case ' => [
216
+ 'testMarker ' => ' /* testReadonlyUsedAsNamespaceName */ ' ,
217
+ 'testContent ' => ' Readonly ' ,
254
218
],
255
- [
256
- '/* testReadonlyUsedAsPartOfNamespaceName */ ' ,
257
- 'Readonly ' ,
219
+ ' partial name of namespace, context: declaration, mixed case ' => [
220
+ 'testMarker ' => ' /* testReadonlyUsedAsPartOfNamespaceName */ ' ,
221
+ 'testContent ' => ' Readonly ' ,
258
222
],
259
- [
260
- '/* testReadonlyAsFunctionCall */ ' ,
261
- 'readonly ' ,
223
+ 'name of a function, context: call ' => [
224
+ 'testMarker ' => '/* testReadonlyAsFunctionCall */ ' ,
262
225
],
263
- [
264
- '/* testReadonlyAsNamespacedFunctionCall */ ' ,
265
- 'readonly ' ,
226
+ 'name of a namespaced function, context: partially qualified call ' => [
227
+ 'testMarker ' => '/* testReadonlyAsNamespacedFunctionCall */ ' ,
266
228
],
267
- [
268
- '/* testReadonlyAsNamespaceRelativeFunctionCall */ ' ,
269
- 'ReadOnly ' ,
229
+ ' name of a function, context: namespace relative call, mixed case ' => [
230
+ 'testMarker ' => ' /* testReadonlyAsNamespaceRelativeFunctionCall */ ' ,
231
+ 'testContent ' => ' ReadOnly ' ,
270
232
],
271
- [
272
- '/* testReadonlyAsMethodCall */ ' ,
273
- 'readonly ' ,
233
+ 'name of a method, context: method call on object ' => [
234
+ 'testMarker ' => '/* testReadonlyAsMethodCall */ ' ,
274
235
],
275
- [
276
- '/* testReadonlyAsNullsafeMethodCall */ ' ,
277
- 'readOnly ' ,
236
+ ' name of a method, context: nullsafe method call on object ' => [
237
+ 'testMarker ' => ' /* testReadonlyAsNullsafeMethodCall */ ' ,
238
+ 'testContent ' => ' readOnly ' ,
278
239
],
279
- [
280
- '/* testReadonlyAsStaticMethodCallWithSpace */ ' ,
281
- 'readonly ' ,
240
+ 'name of a method, context: static method call with space after ' => [
241
+ 'testMarker ' => '/* testReadonlyAsStaticMethodCallWithSpace */ ' ,
282
242
],
283
- [
284
- '/* testClassConstantFetchWithReadonlyAsConstantName */ ' ,
285
- 'READONLY ' ,
243
+ ' name of a constant, context: constant access - uppercase ' => [
244
+ 'testMarker ' => ' /* testClassConstantFetchWithReadonlyAsConstantName */ ' ,
245
+ 'testContent ' => ' READONLY ' ,
286
246
],
287
- [
288
- '/* testReadonlyUsedAsFunctionCallWithSpaceBetweenKeywordAndParens */ ' ,
289
- 'readonly ' ,
247
+ 'name of a function, context: call with space and comment between keyword and parens ' => [
248
+ 'testMarker ' => '/* testReadonlyUsedAsFunctionCallWithSpaceBetweenKeywordAndParens */ ' ,
290
249
],
291
- [
292
- '/* testReadonlyUsedAsMethodNameWithDNFParam */ ' ,
293
- 'readonly ' ,
250
+ 'name of a method, context: declaration with DNF parameter ' => [
251
+ 'testMarker ' => '/* testReadonlyUsedAsMethodNameWithDNFParam */ ' ,
294
252
],
295
253
];
296
254
0 commit comments