PhpdocReadonlyClassCommentToKeywordFixerTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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\ClassNotation;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Marcel Behrmann <marcel@behrmann.dev>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\ClassNotation\PhpdocReadonlyClassCommentToKeywordFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\ClassNotation\PhpdocReadonlyClassCommentToKeywordFixer>
  22. */
  23. final class PhpdocReadonlyClassCommentToKeywordFixerTest extends AbstractFixerTestCase
  24. {
  25. /**
  26. * @dataProvider provideFixCases
  27. *
  28. * @requires PHP 8.2
  29. */
  30. public function testFix(string $expected, ?string $input = null): void
  31. {
  32. $this->doTest($expected, $input);
  33. }
  34. /**
  35. * @return iterable<array{0: string, 1?: string}>
  36. */
  37. public static function provideFixCases(): iterable
  38. {
  39. yield [
  40. <<<'EOT'
  41. <?php
  42. readonly class C {
  43. }
  44. EOT,
  45. <<<'EOT'
  46. <?php
  47. /** @readonly */
  48. class C {
  49. }
  50. EOT,
  51. ];
  52. yield [
  53. <<<'EOT'
  54. <?php
  55. /**
  56. */
  57. readonly class C {
  58. }
  59. EOT,
  60. <<<'EOT'
  61. <?php
  62. /**
  63. * @readonly
  64. */
  65. class C {
  66. }
  67. EOT,
  68. ];
  69. yield [
  70. <<<'EOT'
  71. <?php
  72. /**
  73. * Very impressive class
  74. *
  75. */
  76. readonly class C {
  77. }
  78. EOT,
  79. <<<'EOT'
  80. <?php
  81. /**
  82. * Very impressive class
  83. *
  84. * @readonly
  85. */
  86. class C {
  87. }
  88. EOT,
  89. ];
  90. yield [
  91. <<<'EOT'
  92. <?php
  93. /**
  94. */
  95. final readonly class C {
  96. }
  97. EOT,
  98. <<<'EOT'
  99. <?php
  100. /**
  101. * @readonly
  102. */
  103. final class C {
  104. }
  105. EOT,
  106. ];
  107. yield [
  108. <<<'EOT'
  109. <?php
  110. /**
  111. */
  112. abstract readonly class C {
  113. }
  114. EOT,
  115. <<<'EOT'
  116. <?php
  117. /**
  118. * @readonly
  119. */
  120. abstract class C {
  121. }
  122. EOT,
  123. ];
  124. yield [
  125. <<<'EOT'
  126. <?php
  127. /**
  128. */
  129. readonly class A {
  130. }
  131. EOT,
  132. <<<'EOT'
  133. <?php
  134. /**
  135. * @readonly
  136. */
  137. readonly class A {
  138. }
  139. EOT,
  140. ];
  141. yield [
  142. <<<'EOT'
  143. <?php
  144. /** Class A. */
  145. class A {
  146. }
  147. EOT,
  148. ];
  149. }
  150. }