Skip to content

Commit

Permalink
fix: PhpUnitMethodCasingFixer - do not double underscore (#7949)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Apr 15, 2024
1 parent 8a115cd commit 0e9f115
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private function __construct()
*/
public static function camelCaseToUnderscore(string $string): string
{
return mb_strtolower(Preg::replace('/(?<!^)((?=[\p{Lu}][^\p{Lu}])|(?<![\p{Lu}])(?=[\p{Lu}]))/', '_', $string));
return mb_strtolower(Preg::replace('/(?<!^)(?<!_)((?=[\p{Lu}][^\p{Lu}])|(?<![\p{Lu}])(?=[\p{Lu}]))/', '_', $string));
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/Fixer/PhpUnit/PhpUnitMethodCasingFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ public function notATestEither() {}

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

yield 'mixed case to camel case' => [
'<?php class MyTest extends TestCase { function testShouldNotFooWhenBar() {} }',
'<?php class MyTest extends TestCase { function test_should_notFoo_When_Bar() {} }',
];

yield 'mixed case to snake case' => [
'<?php class MyTest extends TestCase { function test_should_not_foo_when_bar() {} }',
'<?php class MyTest extends TestCase { function test_should_notFoo_When_Bar() {} }',
['case' => 'snake_case'],
];
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ public static function provideCamelCaseToUnderscoreCases(): iterable
'voyage_éclair',
'VoyageÉclair',
];

yield [
'i_want_to_fully_be_a_snake',
'i_wantTo_fully_be_A_Snake',
];
}

/**
Expand Down

0 comments on commit 0e9f115

Please sign in to comment.