PhpdocNoEmptyReturnFixerTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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\PhpdocNoEmptyReturnFixer
  20. */
  21. final class PhpdocNoEmptyReturnFixerTest extends AbstractFixerTestCase
  22. {
  23. public function testFixVoid(): void
  24. {
  25. $expected = <<<'EOF'
  26. <?php
  27. /**
  28. */
  29. EOF;
  30. $input = <<<'EOF'
  31. <?php
  32. /**
  33. * @return void
  34. */
  35. EOF;
  36. $this->doTest($expected, $input);
  37. }
  38. public function testFixNull(): void
  39. {
  40. $expected = <<<'EOF'
  41. <?php
  42. /**
  43. */
  44. EOF;
  45. $input = <<<'EOF'
  46. <?php
  47. /**
  48. * @return null
  49. */
  50. EOF;
  51. $this->doTest($expected, $input);
  52. }
  53. public function testFixNullWithEndOnSameLine(): void
  54. {
  55. $expected = <<<'EOF'
  56. <?php
  57. /**
  58. */
  59. EOF;
  60. $input = <<<'EOF'
  61. <?php
  62. /**
  63. * @return null */
  64. EOF;
  65. $this->doTest($expected, $input);
  66. }
  67. public function testFixNullWithEndOnSameLineNoSpace(): void
  68. {
  69. $expected = <<<'EOF'
  70. <?php
  71. /**
  72. */
  73. EOF;
  74. $input = <<<'EOF'
  75. <?php
  76. /**
  77. * @return null*/
  78. EOF;
  79. $this->doTest($expected, $input);
  80. }
  81. public function testFixVoidCaseInsensitive(): void
  82. {
  83. $expected = <<<'EOF'
  84. <?php
  85. /**
  86. */
  87. EOF;
  88. $input = <<<'EOF'
  89. <?php
  90. /**
  91. * @return vOId
  92. */
  93. EOF;
  94. $this->doTest($expected, $input);
  95. }
  96. public function testFixNullCaseInsensitive(): void
  97. {
  98. $expected = <<<'EOF'
  99. <?php
  100. /**
  101. */
  102. EOF;
  103. $input = <<<'EOF'
  104. <?php
  105. /**
  106. * @return nULl
  107. */
  108. EOF;
  109. $this->doTest($expected, $input);
  110. }
  111. public function testFixFull(): void
  112. {
  113. $expected = <<<'EOF'
  114. <?php
  115. /**
  116. * Hello!
  117. *
  118. * @param string $foo
  119. */
  120. EOF;
  121. $input = <<<'EOF'
  122. <?php
  123. /**
  124. * Hello!
  125. *
  126. * @param string $foo
  127. * @return void
  128. */
  129. EOF;
  130. $this->doTest($expected, $input);
  131. }
  132. public function testDoNothing(): void
  133. {
  134. $expected = <<<'EOF'
  135. <?php
  136. /**
  137. * @var null
  138. */
  139. EOF;
  140. $this->doTest($expected);
  141. }
  142. public function testDoNothingAgain(): void
  143. {
  144. $expected = <<<'EOF'
  145. <?php
  146. /**
  147. * @return null|int
  148. */
  149. EOF;
  150. $this->doTest($expected);
  151. }
  152. public function testOtherDoNothing(): void
  153. {
  154. $expected = <<<'EOF'
  155. <?php
  156. /**
  157. * @return int|null
  158. */
  159. EOF;
  160. $this->doTest($expected);
  161. }
  162. public function testYetAnotherDoNothing(): void
  163. {
  164. $expected = <<<'EOF'
  165. <?php
  166. /**
  167. * @return null[]|string[]
  168. */
  169. EOF;
  170. $this->doTest($expected);
  171. }
  172. public function testHandleSingleLinePhpdoc(): void
  173. {
  174. $expected = <<<'EOF'
  175. <?php
  176. EOF;
  177. $input = <<<'EOF'
  178. <?php
  179. /** @return null */
  180. EOF;
  181. $this->doTest($expected, $input);
  182. }
  183. }