PhpUnitMethodCasingFixerTest.php 4.3 KB

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