PhpdocVarAnnotationCorrectOrderFixerTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. * @internal
  16. *
  17. * @author Kuba Werłos <werlos@gmail.com>
  18. *
  19. * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocVarAnnotationCorrectOrderFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Phpdoc\PhpdocVarAnnotationCorrectOrderFixer>
  22. */
  23. final class PhpdocVarAnnotationCorrectOrderFixerTest extends AbstractFixerTestCase
  24. {
  25. /**
  26. * @dataProvider provideFixCases
  27. */
  28. public function testFix(string $expected, ?string $input = null): void
  29. {
  30. $this->doTest($expected, $input);
  31. }
  32. /**
  33. * @return iterable<array{0: string, 1?: string}>
  34. */
  35. public static function provideFixCases(): iterable
  36. {
  37. yield [ // It's @param, we care only about @var
  38. '<?php /** @param $foo Foo */',
  39. ];
  40. yield [ // This is already fine
  41. '<?php /** @var Foo $foo */ ',
  42. ];
  43. yield [ // What? Two variables, I'm not touching this
  44. '<?php /** @var $foo $bar */',
  45. ];
  46. yield [ // Two classes are not to touch either
  47. '<?php /** @var Foo Bar */',
  48. ];
  49. yield ['<?php /** @var */'];
  50. yield ['<?php /** @var $foo */'];
  51. yield ['<?php /** @var Bar */'];
  52. yield [
  53. '<?php
  54. /**
  55. * @var Foo $foo
  56. * @var Bar $bar
  57. */
  58. ',
  59. '<?php
  60. /**
  61. * @var $foo Foo
  62. * @var $bar Bar
  63. */
  64. ',
  65. ];
  66. yield [
  67. '<?php
  68. /**
  69. * @var Foo $foo Some description
  70. */
  71. ',
  72. '<?php
  73. /**
  74. * @var $foo Foo Some description
  75. */
  76. ',
  77. ];
  78. yield [
  79. '<?php /** @var Foo $foo */',
  80. '<?php /** @var $foo Foo */',
  81. ];
  82. yield [
  83. '<?php /** @type Foo $foo */',
  84. '<?php /** @type $foo Foo */',
  85. ];
  86. yield [
  87. '<?php /** @var Foo $foo*/',
  88. '<?php /** @var $foo Foo*/',
  89. ];
  90. yield [
  91. '<?php /** @var Foo[] $foos */',
  92. '<?php /** @var $foos Foo[] */',
  93. ];
  94. yield [
  95. '<?php /** @Var Foo $foo */',
  96. '<?php /** @Var $foo Foo */',
  97. ];
  98. yield [
  99. '<?php
  100. /** @var Foo|Bar|mixed|int $someWeirdLongNAME__123 */
  101. ',
  102. '<?php
  103. /** @var $someWeirdLongNAME__123 Foo|Bar|mixed|int */
  104. ',
  105. ];
  106. yield [
  107. '<?php
  108. /**
  109. * @var Foo $bar long description
  110. * goes here
  111. */
  112. ',
  113. '<?php
  114. /**
  115. * @var $bar Foo long description
  116. * goes here
  117. */
  118. ',
  119. ];
  120. yield [
  121. '<?php
  122. /** @var array<int, int> $foo */
  123. ',
  124. '<?php
  125. /** @var $foo array<int, int> */
  126. ',
  127. ];
  128. yield [
  129. '<?php
  130. /** @var array<int, int> $foo Array of something */
  131. ',
  132. '<?php
  133. /** @var $foo array<int, int> Array of something */
  134. ',
  135. ];
  136. yield [
  137. '<?php
  138. /** @var Foo|array<int, int>|null $foo */
  139. ',
  140. '<?php
  141. /** @var $foo Foo|array<int, int>|null */
  142. ',
  143. ];
  144. yield [
  145. '<?php
  146. class Foo
  147. {
  148. /**
  149. * @var $bar
  150. */
  151. private $bar;
  152. }
  153. ',
  154. ];
  155. }
  156. }