From 0f732e0293204865ccaf42a7537936ca0b262e42 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Fri, 11 Oct 2024 00:28:59 +1100 Subject: [PATCH] [1.x] Enforce `snake_case` methods for PHPUnit method in Laravel preset (#300) * Use snake_case for PHPUnit method names * Sort --- resources/presets/laravel.php | 1 + tests/Feature/Fixers/PhpUnitCasingTest.php | 18 ++++++++++++++++++ .../Fixtures/fixers/phpunit_method_casing.php | 13 +++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 tests/Feature/Fixers/PhpUnitCasingTest.php create mode 100644 tests/Fixtures/fixers/phpunit_method_casing.php diff --git a/resources/presets/laravel.php b/resources/presets/laravel.php index 98666f48..0ed92749 100644 --- a/resources/presets/laravel.php +++ b/resources/presets/laravel.php @@ -141,6 +141,7 @@ 'ordered_imports' => ['sort_algorithm' => 'alpha', 'imports_order' => ['const', 'class', 'function']], 'ordered_interfaces' => true, 'ordered_traits' => true, + 'php_unit_method_casing' => ['case' => 'snake_case'], 'phpdoc_align' => [ 'align' => 'left', 'spacing' => [ diff --git a/tests/Feature/Fixers/PhpUnitCasingTest.php b/tests/Feature/Fixers/PhpUnitCasingTest.php new file mode 100644 index 00000000..49f698fc --- /dev/null +++ b/tests/Feature/Fixers/PhpUnitCasingTest.php @@ -0,0 +1,18 @@ + base_path('tests/Fixtures/fixers/phpunit_method_casing.php'), + '--preset' => 'laravel', + ]); + + expect($statusCode)->toBe(1) + ->and($output) + ->toContain(' тип '.join_paths('tests', 'Fixtures', 'fixers', 'phpunit_method_casing.php')) + ->toContain(<<<'DIFF' + - public function testItConvertsToSnakeCase() + + public function test_it_converts_to_snake_case() + DIFF); +}); diff --git a/tests/Fixtures/fixers/phpunit_method_casing.php b/tests/Fixtures/fixers/phpunit_method_casing.php new file mode 100644 index 00000000..9726464f --- /dev/null +++ b/tests/Fixtures/fixers/phpunit_method_casing.php @@ -0,0 +1,13 @@ +assertTrue(true); + } +}