PhpdocAnnotationWithoutDotFixerTest.php 6.7 KB

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