PhpdocOrderFixerTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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\PhpdocOrderFixer
  19. */
  20. final class PhpdocOrderFixerTest extends AbstractFixerTestCase
  21. {
  22. public function testNoChanges()
  23. {
  24. $expected = <<<'EOF'
  25. <?php
  26. /**
  27. * Do some cool stuff.
  28. *
  29. * @param EngineInterface $templating
  30. * @param string $name
  31. *
  32. * @throws Exception
  33. *
  34. * @return void|bar
  35. */
  36. EOF;
  37. $this->doTest($expected);
  38. }
  39. public function testOnlyParams()
  40. {
  41. $expected = <<<'EOF'
  42. <?php
  43. /**
  44. * @param EngineInterface $templating
  45. * @param string $name
  46. */
  47. EOF;
  48. $this->doTest($expected);
  49. }
  50. public function testOnlyReturns()
  51. {
  52. $expected = <<<'EOF'
  53. <?php
  54. /**
  55. *
  56. * @return void|bar
  57. *
  58. */
  59. EOF;
  60. $this->doTest($expected);
  61. }
  62. public function testEmpty()
  63. {
  64. $this->doTest('/***/');
  65. }
  66. public function testNoAnnotations()
  67. {
  68. $expected = <<<'EOF'
  69. <?php
  70. /**
  71. *
  72. *
  73. *
  74. */
  75. EOF;
  76. $this->doTest($expected);
  77. }
  78. public function testFixBasicCase()
  79. {
  80. $expected = <<<'EOF'
  81. <?php
  82. /**
  83. * @param string $foo
  84. * @throws Exception
  85. * @return bool
  86. */
  87. EOF;
  88. $input = <<<'EOF'
  89. <?php
  90. /**
  91. * @throws Exception
  92. * @return bool
  93. * @param string $foo
  94. */
  95. EOF;
  96. $this->doTest($expected, $input);
  97. }
  98. public function testFixCompeteCase()
  99. {
  100. $expected = <<<'EOF'
  101. <?php
  102. /**
  103. * Hello there!
  104. *
  105. * Long description
  106. * goes here.
  107. *
  108. * @internal
  109. *
  110. *
  111. * @custom Test!
  112. * asldnaksdkjasdasd
  113. *
  114. *
  115. *
  116. * @param string $foo
  117. * @param bool $bar Bar
  118. * @throws Exception|RuntimeException dfsdf
  119. * jkaskdnaksdnkasndansdnansdajsdnkasd
  120. * @return bool Return false on failure.
  121. * @return int Return the number of changes.
  122. */
  123. EOF;
  124. $input = <<<'EOF'
  125. <?php
  126. /**
  127. * Hello there!
  128. *
  129. * Long description
  130. * goes here.
  131. *
  132. * @internal
  133. *
  134. * @throws Exception|RuntimeException dfsdf
  135. * jkaskdnaksdnkasndansdnansdajsdnkasd
  136. *
  137. * @custom Test!
  138. * asldnaksdkjasdasd
  139. *
  140. *
  141. * @return bool Return false on failure.
  142. * @return int Return the number of changes.
  143. *
  144. * @param string $foo
  145. * @param bool $bar Bar
  146. */
  147. EOF;
  148. $this->doTest($expected, $input);
  149. }
  150. public function testExampleFromSymfony()
  151. {
  152. $expected = <<<'EOF'
  153. <?php
  154. /**
  155. * Renders a template.
  156. *
  157. * @param mixed $name A template name
  158. * @param array $parameters An array of parameters to pass to the template
  159. *
  160. * @throws \InvalidArgumentException if the template does not exist
  161. * @throws \RuntimeException if the template cannot be rendered
  162. * @return string The evaluated template as a string
  163. *
  164. */
  165. EOF;
  166. $input = <<<'EOF'
  167. <?php
  168. /**
  169. * Renders a template.
  170. *
  171. * @param mixed $name A template name
  172. * @param array $parameters An array of parameters to pass to the template
  173. *
  174. * @return string The evaluated template as a string
  175. *
  176. * @throws \InvalidArgumentException if the template does not exist
  177. * @throws \RuntimeException if the template cannot be rendered
  178. */
  179. EOF;
  180. $this->doTest($expected, $input);
  181. }
  182. }