GeneralPhpdocAnnotationRemoveFixerTest.php 4.0 KB

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