GeneralPhpdocAnnotationRemoveFixerTest.php 3.3 KB

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