GetClassToClassKeywordFixerTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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\LanguageConstruct;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author John Paul E. Balandan, CPA <paulbalandan@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\LanguageConstruct\GetClassToClassKeywordFixer
  20. *
  21. * @requires PHP 8.0
  22. *
  23. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\LanguageConstruct\GetClassToClassKeywordFixer>
  24. */
  25. final class GetClassToClassKeywordFixerTest extends AbstractFixerTestCase
  26. {
  27. /**
  28. * @dataProvider provideFixCases
  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. '
  41. <?php
  42. $before = $before::class;
  43. $after = $after::class;
  44. ',
  45. '
  46. <?php
  47. $before = get_class($before);
  48. $after = get_class($after);
  49. ',
  50. ];
  51. yield [
  52. '<?php $abc::class;',
  53. '<?php get_class($abc);',
  54. ];
  55. yield [
  56. '<?php $a::class ;',
  57. '<?php get_class( $a );',
  58. ];
  59. yield [
  60. '<?php $b::class;',
  61. '<?php \get_class($b);',
  62. ];
  63. yield [
  64. '<?php $c::class;',
  65. '<?php GET_class($c);',
  66. ];
  67. yield [
  68. '<?php $d::class/* a */;',
  69. '<?php get_class($d/* a */);',
  70. ];
  71. yield [
  72. '<?php $e::class /** b */;',
  73. '<?php get_class($e /** b */);',
  74. ];
  75. yield [
  76. '<?php $f::class ;',
  77. '<?php get_class ( $f );',
  78. ];
  79. yield [
  80. '<?php $g::class/* x */ /* y */;',
  81. '<?php \get_class(/* x */ $g /* y */);',
  82. ];
  83. yield [
  84. '<?php $h::class;',
  85. '<?php get_class(($h));',
  86. ];
  87. yield [
  88. "<?php\necho \$bar::class\n \n;\n",
  89. "<?php\necho get_class(\n \$bar\n);\n",
  90. ];
  91. yield [
  92. '<?php get_class;',
  93. ];
  94. yield [
  95. '<?php get_class($this);',
  96. ];
  97. yield [
  98. '<?php get_class();',
  99. ];
  100. yield [
  101. '<?php get_class(/* $a */);',
  102. ];
  103. yield [
  104. '<?php get_class(/** $date */);',
  105. ];
  106. yield [
  107. '<?php $a = get_class(12);',
  108. ];
  109. yield [
  110. '<?php get_class($a.$b);',
  111. ];
  112. yield [
  113. '<?php get_class($a === $b);',
  114. ];
  115. yield [
  116. '<?php get_class($foo->bar);',
  117. ];
  118. yield [
  119. '<?php get_class($$foo);',
  120. ];
  121. yield [
  122. '<?php get_class($arr[$bar]);',
  123. ];
  124. yield [
  125. '<?php \a\get_class($foo);',
  126. ];
  127. yield [
  128. '<?php
  129. class A
  130. {
  131. public function get_class($foo) {}
  132. }
  133. ',
  134. ];
  135. yield [
  136. '<?php get_class($a, $b);',
  137. ];
  138. }
  139. }