Skip to content

Commit 8713dfd

Browse files
authored
DX: cleanup PhpUnitMethodCasingFixerTest (#7948)
1 parent ce40b80 commit 8713dfd

File tree

2 files changed

+76
-81
lines changed

2 files changed

+76
-81
lines changed

tests/Fixer/PhpUnit/PhpUnitMethodCasingFixerTest.php

Lines changed: 76 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
namespace PhpCsFixer\Tests\Fixer\PhpUnit;
1616

17-
use PhpCsFixer\Fixer\PhpUnit\PhpUnitMethodCasingFixer;
1817
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
1918

2019
/**
@@ -27,27 +26,13 @@
2726
final class PhpUnitMethodCasingFixerTest extends AbstractFixerTestCase
2827
{
2928
/**
29+
* @param array{case?: 'camel_case'|'snake_case'} $configuration
30+
*
3031
* @dataProvider provideFixCases
3132
*/
32-
public function testFixToCamelCase(string $expected, ?string $input = null): void
33+
public function testFix(string $expected, ?string $input = null, array $configuration = []): void
3334
{
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);
5136
$this->doTest($expected, $input);
5237
}
5338

@@ -67,6 +52,78 @@ public function notATestEither() {}
6752
}',
6853
];
6954

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+
{
70127
yield 'default sample' => [
71128
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase { public function testMyApp() {} }',
72129
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase { public function test_my_app() {} }',
@@ -171,64 +228,4 @@ public function my_app_not_2() {}
171228
}',
172229
];
173230
}
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-
}
234231
}

tests/Test/AbstractFixerTestCase.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
use PhpCsFixer\Tests\Fixer\PhpTag\NoClosingTagFixerTest;
8282
use PhpCsFixer\Tests\Fixer\PhpUnit\PhpUnitConstructFixerTest;
8383
use PhpCsFixer\Tests\Fixer\PhpUnit\PhpUnitDedicateAssertFixerTest;
84-
use PhpCsFixer\Tests\Fixer\PhpUnit\PhpUnitMethodCasingFixerTest;
8584
use PhpCsFixer\Tests\Fixer\PhpUnit\PhpUnitTestCaseStaticMethodCallsFixerTest;
8685
use PhpCsFixer\Tests\Fixer\ReturnNotation\ReturnAssignmentFixerTest;
8786
use PhpCsFixer\Tests\Fixer\Semicolon\MultilineWhitespaceBeforeSemicolonsFixerTest;
@@ -501,7 +500,6 @@ final public function testProperMethodNaming(): void
501500
PhpdocVarWithoutNameFixerTest::class,
502501
PhpUnitConstructFixerTest::class,
503502
PhpUnitDedicateAssertFixerTest::class,
504-
PhpUnitMethodCasingFixerTest::class,
505503
PhpUnitTestCaseStaticMethodCallsFixerTest::class,
506504
ReturnAssignmentFixerTest::class,
507505
ReturnTypeDeclarationFixerTest::class,

0 commit comments

Comments
 (0)