@@ -24,117 +24,345 @@ final class IsCamelCapsTest extends TestCase
24
24
/**
25
25
* Test valid public function/method names.
26
26
*
27
+ * @param string $name The tested name.
28
+ * @param bool $strict Value of the $strict flag.
29
+ *
30
+ * @dataProvider dataValidNotClassFormatPublic
31
+ *
27
32
* @return void
28
33
*/
29
- public function testValidNotClassFormatPublic ()
34
+ public function testValidNotClassFormatPublic ($ name , $ strict )
30
35
{
31
- $ this ->assertTrue (Common::isCamelCaps ('thisIsCamelCaps ' , false , true , true ));
32
- $ this ->assertTrue (Common::isCamelCaps ('thisISCamelCaps ' , false , true , false ));
36
+ $ this ->assertTrue (Common::isCamelCaps ($ name , false , true , $ strict ));
33
37
34
38
}//end testValidNotClassFormatPublic()
35
39
36
40
41
+ /**
42
+ * Data provider.
43
+ *
44
+ * @see testValidNotClassFormatPublic()
45
+ *
46
+ * @return array<string, array<string, string|bool>>
47
+ */
48
+ public static function dataValidNotClassFormatPublic ()
49
+ {
50
+ return [
51
+ 'lower camelCase string in strict mode ' => [
52
+ 'name ' => 'thisIsCamelCaps ' ,
53
+ 'strict ' => true ,
54
+ ],
55
+ 'lower camelCase string with acronym in relaxed mode ' => [
56
+ 'name ' => 'thisISCamelCaps ' ,
57
+ 'strict ' => false ,
58
+ ],
59
+ ];
60
+
61
+ }//end dataValidNotClassFormatPublic()
62
+
63
+
37
64
/**
38
65
* Test invalid public function/method names.
39
66
*
67
+ * @param string $name The tested name.
68
+ *
69
+ * @dataProvider dataInvalidNotClassFormatPublic
70
+ *
40
71
* @return void
41
72
*/
42
- public function testInvalidNotClassFormatPublic ()
73
+ public function testInvalidNotClassFormatPublic ($ name )
43
74
{
44
- $ this ->assertFalse (Common::isCamelCaps ('_thisIsCamelCaps ' , false , true , true ));
45
- $ this ->assertFalse (Common::isCamelCaps ('thisISCamelCaps ' , false , true , true ));
46
- $ this ->assertFalse (Common::isCamelCaps ('ThisIsCamelCaps ' , false , true , true ));
75
+ $ this ->assertFalse (Common::isCamelCaps ($ name , false , true , true ));
47
76
48
- $ this ->assertFalse (Common::isCamelCaps ('3thisIsCamelCaps ' , false , true , true ));
49
- $ this ->assertFalse (Common::isCamelCaps ('*thisIsCamelCaps ' , false , true , true ));
50
- $ this ->assertFalse (Common::isCamelCaps ('-thisIsCamelCaps ' , false , true , true ));
77
+ }//end testInvalidNotClassFormatPublic()
51
78
52
- $ this ->assertFalse (Common::isCamelCaps ('this*IsCamelCaps ' , false , true , true ));
53
- $ this ->assertFalse (Common::isCamelCaps ('this-IsCamelCaps ' , false , true , true ));
54
- $ this ->assertFalse (Common::isCamelCaps ('this_IsCamelCaps ' , false , true , true ));
55
- $ this ->assertFalse (Common::isCamelCaps ('this_is_camel_caps ' , false , true , true ));
56
79
57
- }//end testInvalidNotClassFormatPublic()
80
+ /**
81
+ * Data provider.
82
+ *
83
+ * @see testInvalidNotClassFormatPublic()
84
+ *
85
+ * @return array<string, array<string, string>>
86
+ */
87
+ public static function dataInvalidNotClassFormatPublic ()
88
+ {
89
+ return [
90
+ 'string with initial underscore (invalid when $public is true) ' => [
91
+ 'name ' => '_thisIsCamelCaps ' ,
92
+ ],
93
+ 'lower camelCase string with acronym (invalid when $strict is true) ' => [
94
+ 'name ' => 'thisISCamelCaps ' ,
95
+ ],
96
+ 'PascalCase string ' => [
97
+ 'name ' => 'ThisIsCamelCaps ' ,
98
+ ],
99
+ 'lower camelCase string with initial digit ' => [
100
+ 'name ' => '3thisIsCamelCaps ' ,
101
+ ],
102
+ 'lower camelCase string with initial [^a-zA-z_] character: * ' => [
103
+ 'name ' => '*thisIsCamelCaps ' ,
104
+ ],
105
+ 'lower camelCase string with initial [^a-zA-z_] character: - ' => [
106
+ 'name ' => '-thisIsCamelCaps ' ,
107
+ ],
108
+ 'lower camelCase string with medial [^a-zA-z_] character: * ' => [
109
+ 'name ' => 'this*IsCamelCaps ' ,
110
+ ],
111
+ 'lower camelCase string with medial [^a-zA-z_] character: - ' => [
112
+ 'name ' => 'this-IsCamelCaps ' ,
113
+ ],
114
+ 'lower camelCase string with single medial underscore ' => [
115
+ 'name ' => 'this_IsCamelCaps ' ,
116
+ ],
117
+ 'snake_case string ' => [
118
+ 'name ' => 'this_is_camel_caps ' ,
119
+ ],
120
+ ];
121
+
122
+ }//end dataInvalidNotClassFormatPublic()
58
123
59
124
60
125
/**
61
126
* Test valid private method names.
62
127
*
128
+ * @param string $name The tested name.
129
+ * @param bool $strict Value of the $strict flag.
130
+ *
131
+ * @dataProvider dataValidNotClassFormatPrivate
132
+ *
63
133
* @return void
64
134
*/
65
- public function testValidNotClassFormatPrivate ()
135
+ public function testValidNotClassFormatPrivate ($ name , $ strict )
66
136
{
67
- $ this ->assertTrue (Common::isCamelCaps ('_thisIsCamelCaps ' , false , false , true ));
68
- $ this ->assertTrue (Common::isCamelCaps ('_thisISCamelCaps ' , false , false , false ));
69
- $ this ->assertTrue (Common::isCamelCaps ('_i18N ' , false , false , true ));
70
- $ this ->assertTrue (Common::isCamelCaps ('_i18n ' , false , false , true ));
137
+ $ this ->assertTrue (Common::isCamelCaps ($ name , false , false , $ strict ));
71
138
72
139
}//end testValidNotClassFormatPrivate()
73
140
74
141
142
+ /**
143
+ * Data provider.
144
+ *
145
+ * @see testValidNotClassFormatPrivate()
146
+ *
147
+ * @return array<string, array<string, string|bool>>
148
+ */
149
+ public static function dataValidNotClassFormatPrivate ()
150
+ {
151
+ return [
152
+ 'lower camelCase string with initial underscore ' => [
153
+ 'name ' => '_thisIsCamelCaps ' ,
154
+ 'strict ' => true ,
155
+ ],
156
+ 'lower camelCase string with acronym and initial underscore ' => [
157
+ 'name ' => '_thisISCamelCaps ' ,
158
+ 'strict ' => false ,
159
+ ],
160
+ '_i18N ' => [
161
+ 'name ' => '_i18N ' ,
162
+ 'strict ' => true ,
163
+ ],
164
+ '_i18n ' => [
165
+ 'name ' => '_i18n ' ,
166
+ 'strict ' => true ,
167
+ ],
168
+ ];
169
+
170
+ }//end dataValidNotClassFormatPrivate()
171
+
172
+
75
173
/**
76
174
* Test invalid private method names.
77
175
*
176
+ * @param string $name The tested name.
177
+ * @param bool $strict Value of the $strict flag.
178
+ *
179
+ * @dataProvider dataInvalidNotClassFormatPrivate
180
+ *
78
181
* @return void
79
182
*/
80
- public function testInvalidNotClassFormatPrivate ()
183
+ public function testInvalidNotClassFormatPrivate ($ name , $ strict )
81
184
{
82
- $ this ->assertFalse (Common::isCamelCaps ('thisIsCamelCaps ' , false , false , true ));
83
- $ this ->assertFalse (Common::isCamelCaps ('_thisISCamelCaps ' , false , false , true ));
84
- $ this ->assertFalse (Common::isCamelCaps ('_ThisIsCamelCaps ' , false , false , true ));
85
- $ this ->assertFalse (Common::isCamelCaps ('__thisIsCamelCaps ' , false , false , true ));
86
- $ this ->assertFalse (Common::isCamelCaps ('__thisISCamelCaps ' , false , false , false ));
87
-
88
- $ this ->assertFalse (Common::isCamelCaps ('3thisIsCamelCaps ' , false , false , true ));
89
- $ this ->assertFalse (Common::isCamelCaps ('*thisIsCamelCaps ' , false , false , true ));
90
- $ this ->assertFalse (Common::isCamelCaps ('-thisIsCamelCaps ' , false , false , true ));
91
- $ this ->assertFalse (Common::isCamelCaps ('_this_is_camel_caps ' , false , false , true ));
185
+ $ this ->assertFalse (Common::isCamelCaps ($ name , false , false , $ strict ));
92
186
93
187
}//end testInvalidNotClassFormatPrivate()
94
188
95
189
190
+ /**
191
+ * Data provider.
192
+ *
193
+ * @see testInvalidNotClassFormatPrivate()
194
+ *
195
+ * @return array<string, array<string, string|bool>>
196
+ */
197
+ public static function dataInvalidNotClassFormatPrivate ()
198
+ {
199
+ return [
200
+ 'lower camelCase string without initial underscore ' => [
201
+ 'name ' => 'thisIsCamelCaps ' ,
202
+ 'strict ' => true ,
203
+ ],
204
+ 'lower camelCase string with initial underscore, but with an acronym, in strict mode ' => [
205
+ 'name ' => '_thisISCamelCaps ' ,
206
+ 'strict ' => true ,
207
+ ],
208
+ 'PascalCase string with initial underscore ' => [
209
+ 'name ' => '_ThisIsCamelCaps ' ,
210
+ 'strict ' => true ,
211
+ ],
212
+ 'lower camelCase string with two initial underscores ' => [
213
+ 'name ' => '__thisIsCamelCaps ' ,
214
+ 'strict ' => true ,
215
+ ],
216
+ 'lower camelCase string with two initial underscores and acronym in relaxed mode ' => [
217
+ 'name ' => '__thisISCamelCaps ' ,
218
+ 'strict ' => false ,
219
+ ],
220
+ 'lower camelCase string with initial digit ' => [
221
+ 'name ' => '3thisIsCamelCaps ' ,
222
+ 'strict ' => true ,
223
+ ],
224
+ 'lower camelCase string with initial [^a-zA-Z_] character: * ' => [
225
+ 'name ' => '*thisIsCamelCaps ' ,
226
+ 'strict ' => true ,
227
+ ],
228
+ 'lower camelCase string with initial [^a-zA-Z_] character: - ' => [
229
+ 'name ' => '-thisIsCamelCaps ' ,
230
+ 'strict ' => true ,
231
+ ],
232
+ 'snake_case string with initial underscore ' => [
233
+ 'name ' => '_this_is_camel_caps ' ,
234
+ 'strict ' => true ,
235
+ ],
236
+ ];
237
+
238
+ }//end dataInvalidNotClassFormatPrivate()
239
+
240
+
96
241
/**
97
242
* Test valid class names.
98
243
*
244
+ * @param string $name The tested name.
245
+ * @param bool $strict Value of the $strict flag.
246
+ *
247
+ * @dataProvider dataValidClassFormatPublic
248
+ *
99
249
* @return void
100
250
*/
101
- public function testValidClassFormatPublic ()
251
+ public function testValidClassFormatPublic ($ name , $ strict )
102
252
{
103
- $ this ->assertTrue (Common::isCamelCaps ('ThisIsCamelCaps ' , true , true , true ));
104
- $ this ->assertTrue (Common::isCamelCaps ('ThisISCamelCaps ' , true , true , false ));
105
- $ this ->assertTrue (Common::isCamelCaps ('This3IsCamelCaps ' , true , true , false ));
253
+ $ this ->assertTrue (Common::isCamelCaps ($ name , true , true , $ strict ));
106
254
107
255
}//end testValidClassFormatPublic()
108
256
109
257
258
+ /**
259
+ * Data provider.
260
+ *
261
+ * @see testValidClassFormatPublic()
262
+ *
263
+ * @return array<string, array<string, string|bool>>
264
+ */
265
+ public static function dataValidClassFormatPublic ()
266
+ {
267
+ return [
268
+ 'PascalCase string ' => [
269
+ 'name ' => 'ThisIsCamelCaps ' ,
270
+ 'strict ' => true ,
271
+ ],
272
+ 'PascalCase string with acronym ' => [
273
+ 'name ' => 'ThisISCamelCaps ' ,
274
+ 'strict ' => false ,
275
+ ],
276
+ 'PascalCase string with digit between words ' => [
277
+ 'name ' => 'This3IsCamelCaps ' ,
278
+ 'strict ' => false ,
279
+ ],
280
+ ];
281
+
282
+ }//end dataValidClassFormatPublic()
283
+
284
+
110
285
/**
111
286
* Test invalid class names.
112
287
*
288
+ * @param string $name The tested name.
289
+ *
290
+ * @dataProvider dataInvalidClassFormat
291
+ *
113
292
* @return void
114
293
*/
115
- public function testInvalidClassFormat ()
294
+ public function testInvalidClassFormat ($ name )
116
295
{
117
- $ this ->assertFalse (Common::isCamelCaps ('thisIsCamelCaps ' , true ));
118
- $ this ->assertFalse (Common::isCamelCaps ('This-IsCamelCaps ' , true ));
119
- $ this ->assertFalse (Common::isCamelCaps ('This_Is_Camel_Caps ' , true ));
296
+ $ this ->assertFalse (Common::isCamelCaps ($ name , true ));
120
297
121
298
}//end testInvalidClassFormat()
122
299
123
300
301
+ /**
302
+ * Data provider.
303
+ *
304
+ * @see testInvalidClassFormat()
305
+ *
306
+ * @return array<string, array<string, string>>
307
+ */
308
+ public static function dataInvalidClassFormat ()
309
+ {
310
+ return [
311
+ 'lower camelCase string ' => [
312
+ 'name ' => 'thisIsCamelCaps ' ,
313
+ ],
314
+ 'PascalCase string with medial illegal character: - ' => [
315
+ 'name ' => 'This-IsCamelCaps ' ,
316
+ ],
317
+ 'capitalised snake case ' => [
318
+ 'name ' => 'This_Is_Camel_Caps ' ,
319
+ ],
320
+ ];
321
+
322
+ }//end dataInvalidClassFormat()
323
+
324
+
124
325
/**
125
326
* Test invalid class names with the private flag set.
126
327
*
127
328
* Note that the private flag is ignored if the class format
128
329
* flag is set, so these names are all invalid.
129
330
*
331
+ * @param string $name The tested name.
332
+ * @param bool $public Value of the $public flag.
333
+ *
334
+ * @dataProvider dataInvalidClassFormatPrivate
335
+ *
130
336
* @return void
131
337
*/
132
- public function testInvalidClassFormatPrivate ()
338
+ public function testInvalidClassFormatPrivate ($ name , $ public )
133
339
{
134
- $ this ->assertFalse (Common::isCamelCaps ('_ThisIsCamelCaps ' , true , true ));
135
- $ this ->assertFalse (Common::isCamelCaps ('_ThisIsCamelCaps ' , true , false ));
340
+ $ this ->assertFalse (Common::isCamelCaps ($ name , true , $ public ));
136
341
137
342
}//end testInvalidClassFormatPrivate()
138
343
139
344
345
+ /**
346
+ * Data provider.
347
+ *
348
+ * @see testInvalidClassFormatPrivate()
349
+ *
350
+ * @return array<string, array<string, string|bool>>
351
+ */
352
+ public static function dataInvalidClassFormatPrivate ()
353
+ {
354
+ return [
355
+ 'PascalCase string with initial underscore (public) ' => [
356
+ 'name ' => '_ThisIsCamelCaps ' ,
357
+ 'public ' => true ,
358
+ ],
359
+ 'PascalCase string with initial underscore (private) ' => [
360
+ 'name ' => '_ThisIsCamelCaps ' ,
361
+ 'public ' => false ,
362
+ ],
363
+ ];
364
+
365
+ }//end dataInvalidClassFormatPrivate()
366
+
367
+
140
368
}//end class
0 commit comments