PhpdocTrimFixerTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 Graham Campbell <hello@gjcampbell.co.uk>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer>
  22. */
  23. final class PhpdocTrimFixerTest 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{string}>
  34. */
  35. public static function provideFixCases(): iterable
  36. {
  37. yield [
  38. <<<'EOF'
  39. <?php
  40. /**
  41. * @param EngineInterface $templating
  42. *
  43. * @return void
  44. */
  45. EOF,
  46. ];
  47. yield [
  48. '<?php
  49. /**
  50. * @return int количество деактивированных
  51. */
  52. function deactivateCompleted()
  53. {
  54. return 0;
  55. }',
  56. ];
  57. yield [
  58. mb_convert_encoding('
  59. <?php
  60. /**
  61. * Test à
  62. */
  63. function foo(){}
  64. ', 'Windows-1252', 'UTF-8'),
  65. ];
  66. }
  67. public function testFixMore(): void
  68. {
  69. $expected = <<<'EOF'
  70. <?php
  71. /**
  72. * Hello there!
  73. * @internal
  74. *@param string $foo
  75. *@throws Exception
  76. *
  77. *
  78. *
  79. * @return bool
  80. */
  81. EOF;
  82. $input = <<<'EOF'
  83. <?php
  84. /**
  85. *
  86. *
  87. * Hello there!
  88. * @internal
  89. *@param string $foo
  90. *@throws Exception
  91. *
  92. *
  93. *
  94. * @return bool
  95. *
  96. *
  97. */
  98. EOF;
  99. $this->doTest($expected, $input);
  100. }
  101. public function testClassDocBlock(): void
  102. {
  103. $expected = <<<'EOF'
  104. <?php
  105. namespace Foo;
  106. /**
  107. * This is a class that does classy things.
  108. *
  109. * @internal
  110. *
  111. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  112. * @author Graham Campbell <hello@gjcampbell.co.uk>
  113. */
  114. class Bar {}
  115. EOF;
  116. $input = <<<'EOF'
  117. <?php
  118. namespace Foo;
  119. /**
  120. *
  121. *
  122. * This is a class that does classy things.
  123. *
  124. * @internal
  125. *
  126. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  127. * @author Graham Campbell <hello@gjcampbell.co.uk>
  128. *
  129. *
  130. *
  131. */
  132. class Bar {}
  133. EOF;
  134. $this->doTest($expected, $input);
  135. }
  136. public function testEmptyDocBlock(): void
  137. {
  138. $expected = <<<'EOF'
  139. <?php
  140. /**
  141. *
  142. */
  143. EOF;
  144. $this->doTest($expected);
  145. }
  146. public function testEmptyLargerEmptyDocBlock(): void
  147. {
  148. $expected = <<<'EOF'
  149. <?php
  150. /**
  151. *
  152. */
  153. EOF;
  154. $input = <<<'EOF'
  155. <?php
  156. /**
  157. *
  158. *
  159. *
  160. *
  161. */
  162. EOF;
  163. $this->doTest($expected, $input);
  164. }
  165. public function testSuperSimpleDocBlockStart(): void
  166. {
  167. $expected = <<<'EOF'
  168. <?php
  169. /**
  170. * Test.
  171. */
  172. EOF;
  173. $input = <<<'EOF'
  174. <?php
  175. /**
  176. *
  177. * Test.
  178. */
  179. EOF;
  180. $this->doTest($expected, $input);
  181. }
  182. public function testSuperSimpleDocBlockEnd(): void
  183. {
  184. $expected = <<<'EOF'
  185. <?php
  186. /**
  187. * Test.
  188. */
  189. EOF;
  190. $input = <<<'EOF'
  191. <?php
  192. /**
  193. * Test.
  194. *
  195. */
  196. EOF;
  197. $this->doTest($expected, $input);
  198. }
  199. public function testWithLinesWithoutAsterisk(): void
  200. {
  201. $expected = <<<'EOF'
  202. <?php
  203. /**
  204. * Foo
  205. Baz
  206. */
  207. class Foo
  208. {
  209. }
  210. EOF;
  211. $this->doTest($expected);
  212. }
  213. }