PhpdocTrimFixerTest.php 3.5 KB

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