Skip to content

Commit

Permalink
[1.x] Enforce snake_case methods for PHPUnit method in Laravel pres…
Browse files Browse the repository at this point in the history
…et (#300)

* Use snake_case for PHPUnit method names

* Sort
  • Loading branch information
timacdonald authored Oct 10, 2024
1 parent 57383e8 commit 0f732e0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions resources/presets/laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
18 changes: 18 additions & 0 deletions tests/Feature/Fixers/PhpUnitCasingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use function Illuminate\Filesystem\join_paths;

it('fixes the code', function () {
[$statusCode, $output] = run('default', [
'path' => 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);
});
13 changes: 13 additions & 0 deletions tests/Fixtures/fixers/phpunit_method_casing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Tests\Feature;

use Tests\TestCase;

class PhpUnitCasingTest extends TestCase
{
public function testItConvertsToSnakeCase()
{
$this->assertTrue(true);
}
}

0 comments on commit 0f732e0

Please sign in to comment.