GeneralPhpdocAnnotationRemoveFixerTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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\Phpdoc;
  12. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  13. /**
  14. * @internal
  15. *
  16. * @author Gert de Pagter
  17. * @covers \PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer
  18. */
  19. final class GeneralPhpdocAnnotationRemoveFixerTest extends AbstractFixerTestCase
  20. {
  21. /**
  22. * @dataProvider provideFixCases
  23. *
  24. * @param string $expected
  25. * @param null|string $input
  26. */
  27. public function testFix($expected, $input = null, array $config = [])
  28. {
  29. $this->fixer->configure($config);
  30. $this->doTest($expected, $input);
  31. }
  32. /**
  33. * @return array
  34. */
  35. public function provideFixCases()
  36. {
  37. return [
  38. 'An Annotation gets removed' => [
  39. '<?php
  40. /**
  41. * @internal
  42. */
  43. function hello($name)
  44. {
  45. return "hello " . $name;
  46. }',
  47. '<?php
  48. /**
  49. * @internal
  50. * @param string $name
  51. */
  52. function hello($name)
  53. {
  54. return "hello " . $name;
  55. }',
  56. ['annotations' => ['param']],
  57. ],
  58. 'It removes multiple annotations' => [
  59. '<?php
  60. /**
  61. * @author me
  62. * @internal
  63. */
  64. function hello($name)
  65. {
  66. return "hello " . $name;
  67. }',
  68. '<?php
  69. /**
  70. * @author me
  71. * @internal
  72. * @param string $name
  73. * @return string
  74. * @throws \Exception
  75. */
  76. function hello($name)
  77. {
  78. return "hello " . $name;
  79. }',
  80. ['annotations' => ['param', 'return', 'throws']],
  81. ],
  82. 'It does nothing if no configuration is given' => [
  83. '<?php
  84. /**
  85. * @author me
  86. * @internal
  87. * @param string $name
  88. * @return string
  89. * @throws \Exception
  90. */
  91. function hello($name)
  92. {
  93. return "hello " . $name;
  94. }',
  95. ],
  96. 'It works on multiple functions' => [
  97. '<?php
  98. /**
  99. * @param string $name
  100. * @throws \Exception
  101. */
  102. function hello($name)
  103. {
  104. return "hello " . $name;
  105. }
  106. /**
  107. */
  108. function goodBye()
  109. {
  110. return 0;
  111. }
  112. function noComment()
  113. {
  114. callOtherFunction();
  115. }',
  116. '<?php
  117. /**
  118. * @author me
  119. * @internal
  120. * @param string $name
  121. * @return string
  122. * @throws \Exception
  123. */
  124. function hello($name)
  125. {
  126. return "hello " . $name;
  127. }
  128. /**
  129. * @internal
  130. * @author Piet-Henk
  131. * @return int
  132. */
  133. function goodBye()
  134. {
  135. return 0;
  136. }
  137. function noComment()
  138. {
  139. callOtherFunction();
  140. }',
  141. ['annotations' => ['author', 'return', 'internal']],
  142. ],
  143. 'Nothing happens to non doc-block comments' => [
  144. '<?php
  145. /*
  146. * @internal
  147. * @param string $name
  148. */
  149. function hello($name)
  150. {
  151. return "hello " . $name;
  152. }',
  153. null,
  154. ['annotations' => ['internal', 'param', 'return']],
  155. ],
  156. 'Nothing happens if to be deleted annotations are not present' => [
  157. '<?php
  158. /**
  159. * @internal
  160. * @param string $name
  161. */
  162. function hello($name)
  163. {
  164. return "hello " . $name;
  165. }',
  166. null,
  167. ['annotations' => ['author', 'test', 'return', 'deprecated']],
  168. ],
  169. [
  170. '<?php
  171. while ($something = myFunction($foo)) {}
  172. ',
  173. '<?php
  174. /** @noinspection PhpAssignmentInConditionInspection */
  175. while ($something = myFunction($foo)) {}
  176. ',
  177. ['annotations' => ['noinspection']],
  178. ],
  179. ];
  180. }
  181. }