PhpdocAnnotationWithoutDotFixerTest.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocAnnotationWithoutDotFixer
  20. */
  21. final class PhpdocAnnotationWithoutDotFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFixCases
  25. */
  26. public function testFix(string $expected, ?string $input = null): void
  27. {
  28. $this->doTest($expected, $input);
  29. }
  30. public static function provideFixCases(): iterable
  31. {
  32. yield [
  33. '<?php
  34. /**
  35. * Summary.
  36. *
  37. * Description.
  38. *
  39. * @param string|null $str some string
  40. * @param string $ip IPv4 is not lowercased
  41. * @param string $a A
  42. * @param string $a_string a string
  43. * @param string $ab ab
  44. * @param string $t34 T34
  45. * @param string $s S§
  46. * @param string $genrb Optional. The path to the "genrb" executable
  47. * @param string $ellipsis1 Ellipsis is this: ...
  48. * @param string $ellipsis2 Ellipsis is this: 。。。
  49. * @param string $ellipsis3 Ellipsis is this: …
  50. * @param bool $isStr Is it a string?
  51. * @param int $int Some single-line description. With many dots.
  52. * @param int $int Some multiline
  53. * description. With many dots.
  54. *
  55. * @return array result array
  56. *
  57. * @SomeCustomAnnotation This is important sentence that must not be modified.
  58. */',
  59. '<?php
  60. /**
  61. * Summary.
  62. *
  63. * Description.
  64. *
  65. * @param string|null $str Some string.
  66. * @param string $ip IPv4 is not lowercased.
  67. * @param string $a A.
  68. * @param string $a_string A string.
  69. * @param string $ab Ab.
  70. * @param string $t34 T34.
  71. * @param string $s S§.
  72. * @param string $genrb Optional. The path to the "genrb" executable
  73. * @param string $ellipsis1 Ellipsis is this: ...
  74. * @param string $ellipsis2 Ellipsis is this: 。。。
  75. * @param string $ellipsis3 Ellipsis is this: …
  76. * @param bool $isStr Is it a string?
  77. * @param int $int Some single-line description. With many dots.
  78. * @param int $int Some multiline
  79. * description. With many dots.
  80. *
  81. * @return array Result array。
  82. *
  83. * @SomeCustomAnnotation This is important sentence that must not be modified.
  84. */',
  85. ];
  86. yield [
  87. // invalid char inside line won't crash the fixer
  88. '<?php
  89. /**
  90. * @var string this: '.\chr(174).' is an odd character
  91. * @var string This: '.\chr(174).' is an odd character 2nd time。
  92. */',
  93. '<?php
  94. /**
  95. * @var string This: '.\chr(174).' is an odd character.
  96. * @var string This: '.\chr(174).' is an odd character 2nd time。
  97. */',
  98. ];
  99. yield [
  100. '<?php
  101. /**
  102. * @deprecated since version 2. Use emergency() which is PSR-3 compatible.
  103. */',
  104. ];
  105. yield [
  106. '<?php
  107. /**
  108. * @internal This method is public to be usable as callback. It should not
  109. * be used in user code.
  110. */',
  111. ];
  112. yield [
  113. '<?php
  114. /**
  115. * @deprecated this is
  116. * deprecated
  117. */',
  118. '<?php
  119. /**
  120. * @deprecated This is
  121. * deprecated.
  122. */',
  123. ];
  124. yield [
  125. '<?php
  126. /**
  127. * @return bool|null returns `true` if the class has a single-column ID
  128. * and Returns `false` otherwise
  129. */',
  130. '<?php
  131. /**
  132. * @return bool|null Returns `true` if the class has a single-column ID
  133. * and Returns `false` otherwise.
  134. */',
  135. ];
  136. yield [
  137. '<?php
  138. /**
  139. * @throws \Exception having whitespaces after dot, yet I am fixed
  140. */',
  141. '<?php
  142. /**
  143. * @throws \Exception having whitespaces after dot, yet I am fixed. '.'
  144. */',
  145. ];
  146. yield [
  147. '<?php
  148. /**
  149. * @throws \Exception having tabs after dot, yet I am fixed
  150. */',
  151. '<?php
  152. /**
  153. * @throws \Exception having tabs after dot, yet I am fixed. '.'
  154. */',
  155. ];
  156. yield [
  157. '<?php
  158. /**
  159. * Dispatches an event to all registered listeners.
  160. *
  161. * @param string $eventName The name of the event to dispatch. The name of the event is
  162. * the name of the method that is invoked on listeners.
  163. * @param EventArgs $eventArgs The event arguments to pass to the event handlers/listeners.
  164. * If not supplied, the single empty EventArgs instance is used.
  165. *
  166. * @return bool
  167. */
  168. function dispatchEvent($eventName, EventArgs $eventArgs = null) {}
  169. /**
  170. * Extract the `object_to_populate` field from the context if it exists
  171. * and is an instance of the provided $class.
  172. *
  173. * @param string $class The class the object should be
  174. * @param array $context The denormalization context
  175. * @param string $key Key in which to look for the object to populate.
  176. * Keeps backwards compatibility with `AbstractNormalizer`.
  177. *
  178. * @return null|object an object if things check out, null otherwise
  179. */
  180. function extractObjectToPopulate($class, array $context, $key = null) {}
  181. ',
  182. ];
  183. yield [
  184. '<?php
  185. /**
  186. * This is a broken phpdoc - missing asterisk
  187. * @param string $str As it is broken, let us not apply the rule to description of parameter.
  188. */
  189. function foo($str) {}',
  190. ];
  191. yield [
  192. '<?php
  193. /**
  194. * @return bool|null Returns `true` if the class has a single-column ID.
  195. Returns `false` otherwise.
  196. That was multilined comment. With plenty of sentenced.
  197. */
  198. function nothingToDo() {}',
  199. ];
  200. yield [
  201. '<?php
  202. /**
  203. * @param string $bar τάχιστη
  204. */
  205. function foo ($bar) {}
  206. ',
  207. '<?php
  208. /**
  209. * @param string $bar Τάχιστη.
  210. */
  211. function foo ($bar) {}
  212. ',
  213. ];
  214. }
  215. }