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