14
14
15
15
namespace PhpCsFixer \Tests \Fixer \PhpUnit ;
16
16
17
- use PhpCsFixer \Fixer \PhpUnit \PhpUnitMethodCasingFixer ;
18
17
use PhpCsFixer \Tests \Test \AbstractFixerTestCase ;
19
18
20
19
/**
27
26
final class PhpUnitMethodCasingFixerTest extends AbstractFixerTestCase
28
27
{
29
28
/**
29
+ * @param array{case?: 'camel_case'|'snake_case'} $configuration
30
+ *
30
31
* @dataProvider provideFixCases
31
32
*/
32
- public function testFixToCamelCase (string $ expected , ?string $ input = null ): void
33
+ public function testFix (string $ expected , ?string $ input = null , array $ configuration = [] ): void
33
34
{
34
- $ this ->doTest ($ expected , $ input );
35
- }
36
-
37
- /**
38
- * @dataProvider provideFixCases
39
- */
40
- public function testFixToSnakeCase (string $ camelExpected , ?string $ camelInput = null ): void
41
- {
42
- if (null === $ camelInput ) {
43
- $ expected = $ camelExpected ;
44
- $ input = $ camelInput ;
45
- } else {
46
- $ expected = $ camelInput ;
47
- $ input = $ camelExpected ;
48
- }
49
-
50
- $ this ->fixer ->configure (['case ' => PhpUnitMethodCasingFixer::SNAKE_CASE ]);
35
+ $ this ->fixer ->configure ($ configuration );
51
36
$ this ->doTest ($ expected , $ input );
52
37
}
53
38
@@ -67,6 +52,78 @@ public function notATestEither() {}
67
52
} ' ,
68
53
];
69
54
55
+ foreach (self ::pairs () as $ key => [$ camelCase , $ snakeCase ]) {
56
+ yield $ key .' to camel case ' => [$ camelCase , $ snakeCase ];
57
+
58
+ yield $ key .' to snake case ' => [$ snakeCase , $ camelCase , ['case ' => 'snake_case ' ]];
59
+ }
60
+ }
61
+
62
+ /**
63
+ * @dataProvider provideFix80Cases
64
+ *
65
+ * @requires PHP 8.0
66
+ */
67
+ public function testFix80 (string $ expected , string $ input ): void
68
+ {
69
+ $ this ->doTest ($ expected , $ input );
70
+ }
71
+
72
+ /**
73
+ * @return iterable<string, array{string, string}>
74
+ */
75
+ public static function provideFix80Cases (): iterable
76
+ {
77
+ yield '@depends annotation with class name in Snake_Case ' => [
78
+ '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
79
+ public function testMyApp () {}
80
+
81
+ /**
82
+ * @depends Foo_Bar_Test::testMyApp
83
+ */
84
+ #[SimpleTest]
85
+ public function testMyAppToo() {}
86
+ } ' ,
87
+ '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
88
+ public function test_my_app () {}
89
+
90
+ /**
91
+ * @depends Foo_Bar_Test::test_my_app
92
+ */
93
+ #[SimpleTest]
94
+ public function test_my_app_too() {}
95
+ } ' ,
96
+ ];
97
+
98
+ yield '@depends annotation with class name in Snake_Case and attributes in between ' => [
99
+ '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
100
+ public function testMyApp () {}
101
+
102
+ /**
103
+ * @depends Foo_Bar_Test::testMyApp
104
+ */
105
+ #[SimpleTest]
106
+ #[Deprecated]
107
+ public function testMyAppToo() {}
108
+ } ' ,
109
+ '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
110
+ public function test_my_app () {}
111
+
112
+ /**
113
+ * @depends Foo_Bar_Test::test_my_app
114
+ */
115
+ #[SimpleTest]
116
+ #[Deprecated]
117
+ public function test_my_app_too() {}
118
+ } ' ,
119
+ ];
120
+ }
121
+
122
+ /**
123
+ * @return iterable<string, array{string, string}>
124
+ */
125
+ private static function pairs (): iterable
126
+ {
70
127
yield 'default sample ' => [
71
128
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase { public function testMyApp() {} } ' ,
72
129
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase { public function test_my_app() {} } ' ,
@@ -171,64 +228,4 @@ public function my_app_not_2() {}
171
228
} ' ,
172
229
];
173
230
}
174
-
175
- /**
176
- * @dataProvider provideFix80ToCamelCaseCases
177
- *
178
- * @requires PHP 8.0
179
- */
180
- public function testFix80ToCamelCase (string $ expected , string $ input ): void
181
- {
182
- $ this ->doTest ($ expected , $ input );
183
- }
184
-
185
- /**
186
- * @return iterable<string, array{string, string}>
187
- */
188
- public static function provideFix80ToCamelCaseCases (): iterable
189
- {
190
- yield '@depends annotation with class name in Snake_Case ' => [
191
- '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
192
- public function testMyApp () {}
193
-
194
- /**
195
- * @depends Foo_Bar_Test::testMyApp
196
- */
197
- #[SimpleTest]
198
- public function testMyAppToo() {}
199
- } ' ,
200
- '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
201
- public function test_my_app () {}
202
-
203
- /**
204
- * @depends Foo_Bar_Test::test_my_app
205
- */
206
- #[SimpleTest]
207
- public function test_my_app_too() {}
208
- } ' ,
209
- ];
210
-
211
- yield '@depends annotation with class name in Snake_Case and attributes in between ' => [
212
- '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
213
- public function testMyApp () {}
214
-
215
- /**
216
- * @depends Foo_Bar_Test::testMyApp
217
- */
218
- #[SimpleTest]
219
- #[Deprecated]
220
- public function testMyAppToo() {}
221
- } ' ,
222
- '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
223
- public function test_my_app () {}
224
-
225
- /**
226
- * @depends Foo_Bar_Test::test_my_app
227
- */
228
- #[SimpleTest]
229
- #[Deprecated]
230
- public function test_my_app_too() {}
231
- } ' ,
232
- ];
233
- }
234
231
}
0 commit comments