Skip to content

Commit

Permalink
DX: cleanup PhpUnitMethodCasingFixerTest (#7948)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Apr 15, 2024
1 parent ce40b80 commit 8713dfd
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 81 deletions.
155 changes: 76 additions & 79 deletions tests/Fixer/PhpUnit/PhpUnitMethodCasingFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

namespace PhpCsFixer\Tests\Fixer\PhpUnit;

use PhpCsFixer\Fixer\PhpUnit\PhpUnitMethodCasingFixer;
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;

/**
Expand All @@ -27,27 +26,13 @@
final class PhpUnitMethodCasingFixerTest extends AbstractFixerTestCase
{
/**
* @param array{case?: 'camel_case'|'snake_case'} $configuration
*
* @dataProvider provideFixCases
*/
public function testFixToCamelCase(string $expected, ?string $input = null): void
public function testFix(string $expected, ?string $input = null, array $configuration = []): void
{
$this->doTest($expected, $input);
}

/**
* @dataProvider provideFixCases
*/
public function testFixToSnakeCase(string $camelExpected, ?string $camelInput = null): void
{
if (null === $camelInput) {
$expected = $camelExpected;
$input = $camelInput;
} else {
$expected = $camelInput;
$input = $camelExpected;
}

$this->fixer->configure(['case' => PhpUnitMethodCasingFixer::SNAKE_CASE]);
$this->fixer->configure($configuration);
$this->doTest($expected, $input);
}

Expand All @@ -67,6 +52,78 @@ public function notATestEither() {}
}',
];

foreach (self::pairs() as $key => [$camelCase, $snakeCase]) {
yield $key.' to camel case' => [$camelCase, $snakeCase];

yield $key.' to snake case' => [$snakeCase, $camelCase, ['case' => 'snake_case']];
}
}

/**
* @dataProvider provideFix80Cases
*
* @requires PHP 8.0
*/
public function testFix80(string $expected, string $input): void
{
$this->doTest($expected, $input);
}

/**
* @return iterable<string, array{string, string}>
*/
public static function provideFix80Cases(): iterable
{
yield '@depends annotation with class name in Snake_Case' => [
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
public function testMyApp () {}
/**
* @depends Foo_Bar_Test::testMyApp
*/
#[SimpleTest]
public function testMyAppToo() {}
}',
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
public function test_my_app () {}
/**
* @depends Foo_Bar_Test::test_my_app
*/
#[SimpleTest]
public function test_my_app_too() {}
}',
];

yield '@depends annotation with class name in Snake_Case and attributes in between' => [
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
public function testMyApp () {}
/**
* @depends Foo_Bar_Test::testMyApp
*/
#[SimpleTest]
#[Deprecated]
public function testMyAppToo() {}
}',
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
public function test_my_app () {}
/**
* @depends Foo_Bar_Test::test_my_app
*/
#[SimpleTest]
#[Deprecated]
public function test_my_app_too() {}
}',
];
}

/**
* @return iterable<string, array{string, string}>
*/
private static function pairs(): iterable
{
yield 'default sample' => [
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase { public function testMyApp() {} }',
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase { public function test_my_app() {} }',
Expand Down Expand Up @@ -171,64 +228,4 @@ public function my_app_not_2() {}
}',
];
}

/**
* @dataProvider provideFix80ToCamelCaseCases
*
* @requires PHP 8.0
*/
public function testFix80ToCamelCase(string $expected, string $input): void
{
$this->doTest($expected, $input);
}

/**
* @return iterable<string, array{string, string}>
*/
public static function provideFix80ToCamelCaseCases(): iterable
{
yield '@depends annotation with class name in Snake_Case' => [
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
public function testMyApp () {}
/**
* @depends Foo_Bar_Test::testMyApp
*/
#[SimpleTest]
public function testMyAppToo() {}
}',
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
public function test_my_app () {}
/**
* @depends Foo_Bar_Test::test_my_app
*/
#[SimpleTest]
public function test_my_app_too() {}
}',
];

yield '@depends annotation with class name in Snake_Case and attributes in between' => [
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
public function testMyApp () {}
/**
* @depends Foo_Bar_Test::testMyApp
*/
#[SimpleTest]
#[Deprecated]
public function testMyAppToo() {}
}',
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
public function test_my_app () {}
/**
* @depends Foo_Bar_Test::test_my_app
*/
#[SimpleTest]
#[Deprecated]
public function test_my_app_too() {}
}',
];
}
}
2 changes: 0 additions & 2 deletions tests/Test/AbstractFixerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
use PhpCsFixer\Tests\Fixer\PhpTag\NoClosingTagFixerTest;
use PhpCsFixer\Tests\Fixer\PhpUnit\PhpUnitConstructFixerTest;
use PhpCsFixer\Tests\Fixer\PhpUnit\PhpUnitDedicateAssertFixerTest;
use PhpCsFixer\Tests\Fixer\PhpUnit\PhpUnitMethodCasingFixerTest;
use PhpCsFixer\Tests\Fixer\PhpUnit\PhpUnitTestCaseStaticMethodCallsFixerTest;
use PhpCsFixer\Tests\Fixer\ReturnNotation\ReturnAssignmentFixerTest;
use PhpCsFixer\Tests\Fixer\Semicolon\MultilineWhitespaceBeforeSemicolonsFixerTest;
Expand Down Expand Up @@ -501,7 +500,6 @@ final public function testProperMethodNaming(): void
PhpdocVarWithoutNameFixerTest::class,
PhpUnitConstructFixerTest::class,
PhpUnitDedicateAssertFixerTest::class,
PhpUnitMethodCasingFixerTest::class,
PhpUnitTestCaseStaticMethodCallsFixerTest::class,
ReturnAssignmentFixerTest::class,
ReturnTypeDeclarationFixerTest::class,
Expand Down

0 comments on commit 8713dfd

Please sign in to comment.