PhpdocTrimFixerTest.php 4.8 KB

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