GetClassToClassKeywordFixerTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. final class GetClassToClassKeywordFixerTest 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. public static function provideFixCases(): iterable
  33. {
  34. yield [
  35. '
  36. <?php
  37. $before = $before::class;
  38. $after = $after::class;
  39. ',
  40. '
  41. <?php
  42. $before = get_class($before);
  43. $after = get_class($after);
  44. ',
  45. ];
  46. yield [
  47. '<?php $abc::class;',
  48. '<?php get_class($abc);',
  49. ];
  50. yield [
  51. '<?php $a::class ;',
  52. '<?php get_class( $a );',
  53. ];
  54. yield [
  55. '<?php $b::class;',
  56. '<?php \get_class($b);',
  57. ];
  58. yield [
  59. '<?php $c::class;',
  60. '<?php GET_class($c);',
  61. ];
  62. yield [
  63. '<?php $d::class/* a */;',
  64. '<?php get_class($d/* a */);',
  65. ];
  66. yield [
  67. '<?php $e::class /** b */;',
  68. '<?php get_class($e /** b */);',
  69. ];
  70. yield [
  71. '<?php $f::class ;',
  72. '<?php get_class ( $f );',
  73. ];
  74. yield [
  75. '<?php $g::class/* x */ /* y */;',
  76. '<?php \get_class(/* x */ $g /* y */);',
  77. ];
  78. yield [
  79. '<?php $h::class;',
  80. '<?php get_class(($h));',
  81. ];
  82. yield [
  83. "<?php\necho \$bar::class\n \n;\n",
  84. "<?php\necho get_class(\n \$bar\n);\n",
  85. ];
  86. yield [
  87. '<?php get_class;',
  88. ];
  89. yield [
  90. '<?php get_class($this);',
  91. ];
  92. yield [
  93. '<?php get_class();',
  94. ];
  95. yield [
  96. '<?php get_class(/* $a */);',
  97. ];
  98. yield [
  99. '<?php get_class(/** $date */);',
  100. ];
  101. yield [
  102. '<?php $a = get_class(12);',
  103. ];
  104. yield [
  105. '<?php get_class($a.$b);',
  106. ];
  107. yield [
  108. '<?php get_class($a === $b);',
  109. ];
  110. yield [
  111. '<?php get_class($foo->bar);',
  112. ];
  113. yield [
  114. '<?php get_class($$foo);',
  115. ];
  116. yield [
  117. '<?php get_class($arr[$bar]);',
  118. ];
  119. yield [
  120. '<?php \a\get_class($foo);',
  121. ];
  122. yield [
  123. '<?php
  124. class A
  125. {
  126. public function get_class($foo) {}
  127. }
  128. ',
  129. ];
  130. yield [
  131. '<?php get_class($a, $b);',
  132. ];
  133. }
  134. }