PhpdocTypesFixerTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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\AbstractPhpdocTypesFixer
  19. * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocTypesFixer
  20. */
  21. final class PhpdocTypesFixerTest extends AbstractFixerTestCase
  22. {
  23. public function testConversion()
  24. {
  25. $expected = <<<'EOF'
  26. <?php
  27. /**
  28. * @param boolean|array|Foo $bar
  29. *
  30. * @return int|float
  31. */
  32. EOF;
  33. $input = <<<'EOF'
  34. <?php
  35. /**
  36. * @param Boolean|Array|Foo $bar
  37. *
  38. * @return inT|Float
  39. */
  40. EOF;
  41. $this->doTest($expected, $input);
  42. }
  43. public function testArrayStuff()
  44. {
  45. $expected = <<<'EOF'
  46. <?php
  47. /**
  48. * @param string|string[] $bar
  49. *
  50. * @return int[]
  51. */
  52. EOF;
  53. $input = <<<'EOF'
  54. <?php
  55. /**
  56. * @param STRING|String[] $bar
  57. *
  58. * @return inT[]
  59. */
  60. EOF;
  61. $this->doTest($expected, $input);
  62. }
  63. public function testMixedAndVoid()
  64. {
  65. $expected = <<<'EOF'
  66. <?php
  67. /**
  68. * @param mixed $foo
  69. *
  70. * @return void
  71. */
  72. EOF;
  73. $input = <<<'EOF'
  74. <?php
  75. /**
  76. * @param Mixed $foo
  77. *
  78. * @return Void
  79. */
  80. EOF;
  81. $this->doTest($expected, $input);
  82. }
  83. public function testIterableFix()
  84. {
  85. $expected = <<<'EOF'
  86. <?php
  87. /**
  88. * @param iterable $foo
  89. *
  90. * @return Itter
  91. */
  92. EOF;
  93. $input = <<<'EOF'
  94. <?php
  95. /**
  96. * @param Iterable $foo
  97. *
  98. * @return Itter
  99. */
  100. EOF;
  101. $this->doTest($expected, $input);
  102. }
  103. public function testMethodAndPropertyFix()
  104. {
  105. $expected = <<<'EOF'
  106. <?php
  107. /**
  108. * @method self foo()
  109. * @property int $foo
  110. * @property-read boolean $bar
  111. * @property-write mixed $baz
  112. */
  113. EOF;
  114. $input = <<<'EOF'
  115. <?php
  116. /**
  117. * @method Self foo()
  118. * @property Int $foo
  119. * @property-read Boolean $bar
  120. * @property-write MIXED $baz
  121. */
  122. EOF;
  123. $this->doTest($expected, $input);
  124. }
  125. public function testThrows()
  126. {
  127. $expected = <<<'EOF'
  128. <?php
  129. /**
  130. * @throws static
  131. */
  132. EOF;
  133. $input = <<<'EOF'
  134. <?php
  135. /**
  136. * @throws STATIC
  137. */
  138. EOF;
  139. $this->doTest($expected, $input);
  140. }
  141. public function testInlineDoc()
  142. {
  143. $expected = <<<'EOF'
  144. <?php
  145. /**
  146. * Does stuffs with stuffs.
  147. *
  148. * @param array $stuffs {
  149. * @var bool $foo
  150. * @var int $bar
  151. * }
  152. */
  153. EOF;
  154. $input = <<<'EOF'
  155. <?php
  156. /**
  157. * Does stuffs with stuffs.
  158. *
  159. * @param array $stuffs {
  160. * @var Bool $foo
  161. * @var INT $bar
  162. * }
  163. */
  164. EOF;
  165. $this->doTest($expected, $input);
  166. }
  167. }