PhpUnitMethodCasingFixerTest.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Fixer\PhpUnit;
  13. use PhpCsFixer\Fixer\PhpUnit\PhpUnitMethodCasingFixer;
  14. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  15. /**
  16. * @author Filippo Tessarotto <zoeslam@gmail.com>
  17. *
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\Fixer\PhpUnit\PhpUnitMethodCasingFixer
  21. */
  22. final class PhpUnitMethodCasingFixerTest extends AbstractFixerTestCase
  23. {
  24. /**
  25. * @dataProvider provideFixCases
  26. */
  27. public function testFixToCamelCase(string $expected, ?string $input = null): void
  28. {
  29. $this->doTest($expected, $input);
  30. }
  31. /**
  32. * @dataProvider provideFixCases
  33. */
  34. public function testFixToSnakeCase(string $camelExpected, ?string $camelInput = null): void
  35. {
  36. if (null === $camelInput) {
  37. $expected = $camelExpected;
  38. $input = $camelInput;
  39. } else {
  40. $expected = $camelInput;
  41. $input = $camelExpected;
  42. }
  43. $this->fixer->configure(['case' => PhpUnitMethodCasingFixer::SNAKE_CASE]);
  44. $this->doTest($expected, $input);
  45. }
  46. public function provideFixCases(): array
  47. {
  48. return [
  49. 'skip non phpunit methods' => [
  50. '<?php class MyClass {
  51. public function testMyApp() {}
  52. public function test_my_app() {}
  53. }',
  54. ],
  55. 'skip non test methods' => [
  56. '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
  57. public function not_a_test() {}
  58. public function notATestEither() {}
  59. }',
  60. ],
  61. 'default sample' => [
  62. '<?php class MyTest extends \PhpUnit\FrameWork\TestCase { public function testMyApp() {} }',
  63. '<?php class MyTest extends \PhpUnit\FrameWork\TestCase { public function test_my_app() {} }',
  64. ],
  65. 'annotation' => [
  66. '<?php class MyTest extends \PhpUnit\FrameWork\TestCase { /** @test */ public function myApp() {} }',
  67. '<?php class MyTest extends \PhpUnit\FrameWork\TestCase { /** @test */ public function my_app() {} }',
  68. ],
  69. '@depends annotation' => [
  70. '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
  71. public function testMyApp () {}
  72. /**
  73. * @depends testMyApp
  74. */
  75. public function testMyAppToo() {}
  76. }',
  77. '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
  78. public function test_my_app () {}
  79. /**
  80. * @depends test_my_app
  81. */
  82. public function test_my_app_too() {}
  83. }',
  84. ],
  85. '@depends annotation with class name in PascalCase' => [
  86. '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
  87. public function testMyApp () {}
  88. /**
  89. * @depends FooBarTest::testMyApp
  90. */
  91. public function testMyAppToo() {}
  92. }',
  93. '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
  94. public function test_my_app () {}
  95. /**
  96. * @depends FooBarTest::test_my_app
  97. */
  98. public function test_my_app_too() {}
  99. }',
  100. ],
  101. '@depends annotation with class name in Snake_Case' => [
  102. '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
  103. public function testMyApp () {}
  104. /**
  105. * @depends Foo_Bar_Test::testMyApp
  106. */
  107. public function testMyAppToo() {}
  108. }',
  109. '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
  110. public function test_my_app () {}
  111. /**
  112. * @depends Foo_Bar_Test::test_my_app
  113. */
  114. public function test_my_app_too() {}
  115. }',
  116. ],
  117. '@depends and @test annotation' => [
  118. '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
  119. /**
  120. * @test
  121. */
  122. public function myApp () {}
  123. /**
  124. * @test
  125. * @depends myApp
  126. */
  127. public function myAppToo() {}
  128. /** not a test method */
  129. public function my_app_not() {}
  130. public function my_app_not_2() {}
  131. }',
  132. '<?php class MyTest extends \PhpUnit\FrameWork\TestCase {
  133. /**
  134. * @test
  135. */
  136. public function my_app () {}
  137. /**
  138. * @test
  139. * @depends my_app
  140. */
  141. public function my_app_too() {}
  142. /** not a test method */
  143. public function my_app_not() {}
  144. public function my_app_not_2() {}
  145. }',
  146. ],
  147. ];
  148. }
  149. }