Skip to content

Commit

Permalink
bug #5379 PhpUnitMethodCasingFixer - Do not modify class name (localh…
Browse files Browse the repository at this point in the history
…einz)

This PR was squashed before being merged into the 2.17 branch.

Discussion
----------

PhpUnitMethodCasingFixer - Do not modify class name

This PR

* [x] asserts that the `PhpUnitMethodCasingFixer` does not modify class names when using `@depends` annotations with `FooTest::testFoo()` style
* [x] adjusts the `PhpUnitMethodCasingFixer` to fix only the function name part

Commits
-------

6fd0101 PhpUnitMethodCasingFixer - Do not modify class name
  • Loading branch information
keradus committed Jan 18, 2021
2 parents f209e6d + 6fd0101 commit 7c550c6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Fixer/PhpUnit/PhpUnitMethodCasingFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,22 @@ protected function applyPhpUnitClassFix(Tokens $tokens, $startIndex, $endIndex)
*/
private function updateMethodCasing($functionName)
{
$parts = explode('::', $functionName);

$functionNamePart = array_pop($parts);

if (self::CAMEL_CASE === $this->configuration['case']) {
$newFunctionName = $functionName;
$newFunctionName = ucwords($newFunctionName, '_');
$newFunctionName = str_replace('_', '', $newFunctionName);
$newFunctionName = lcfirst($newFunctionName);
$newFunctionNamePart = $functionNamePart;
$newFunctionNamePart = ucwords($newFunctionNamePart, '_');
$newFunctionNamePart = str_replace('_', '', $newFunctionNamePart);
$newFunctionNamePart = lcfirst($newFunctionNamePart);
} else {
$newFunctionName = Utils::camelCaseToUnderscore($functionName);
$newFunctionNamePart = Utils::camelCaseToUnderscore($functionNamePart);
}

return $newFunctionName;
$parts[] = $newFunctionNamePart;

return implode('::', $parts);
}

/**
Expand Down
36 changes: 36 additions & 0 deletions tests/Fixer/PhpUnit/PhpUnitMethodCasingFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,42 @@ public function test_my_app () {}
public function test_my_app_too() {}
}',
],
'@depends annotation with class name in PascalCase' => [
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
public function testMyApp () {}
/**
* @depends FooBarTest::testMyApp
*/
public function testMyAppToo() {}
}',
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
public function test_my_app () {}
/**
* @depends FooBarTest::test_my_app
*/
public function test_my_app_too() {}
}',
],
'@depends annotation with class name in Snake_Case' => [
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
public function testMyApp () {}
/**
* @depends Foo_Bar_Test::testMyApp
*/
public function testMyAppToo() {}
}',
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
public function test_my_app () {}
/**
* @depends Foo_Bar_Test::test_my_app
*/
public function test_my_app_too() {}
}',
],
'@depends and @test annotation' => [
'<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
/**
Expand Down

0 comments on commit 7c550c6

Please sign in to comment.