MagicConstantCasingFixerTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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\Casing;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author ntzm
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Casing\MagicConstantCasingFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Casing\MagicConstantCasingFixer>
  22. */
  23. final class MagicConstantCasingFixerTest 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{string, string}>
  34. */
  35. public static function provideFixCases(): iterable
  36. {
  37. yield [
  38. '<?php echo __LINE__;',
  39. '<?php echo __line__;',
  40. ];
  41. yield [
  42. '<?php echo __FILE__;',
  43. '<?php echo __FILe__;',
  44. ];
  45. yield [
  46. '<?php echo __DIR__;',
  47. '<?php echo __dIr__;',
  48. ];
  49. yield [
  50. '<?php echo __FUNCTION__;',
  51. '<?php echo __fUncTiOn__;',
  52. ];
  53. yield [
  54. '<?php echo __CLASS__;',
  55. '<?php echo __clasS__;',
  56. ];
  57. yield [
  58. '<?php echo __METHOD__;',
  59. '<?php echo __mEthoD__;',
  60. ];
  61. yield [
  62. '<?php echo __NAMESPACE__;',
  63. '<?php echo __namespace__;',
  64. ];
  65. yield [
  66. '<?php echo __TRAIT__;',
  67. '<?php echo __trait__;',
  68. ];
  69. yield [
  70. '<?php echo __TRAIT__;',
  71. '<?php echo __trAIt__;',
  72. ];
  73. yield [
  74. '<?php echo Exception::class;',
  75. '<?php echo Exception::CLASS;',
  76. ];
  77. yield [
  78. '<?php echo Exception::class;',
  79. '<?php echo Exception::ClAss;',
  80. ];
  81. }
  82. /**
  83. * @requires PHP <8.0
  84. *
  85. * @dataProvider provideFixPre80Cases
  86. */
  87. public function testFixPre80(string $expected, ?string $input = null): void
  88. {
  89. $this->doTest($expected, $input);
  90. }
  91. /**
  92. * @return iterable<array{string}>
  93. */
  94. public static function provideFixPre80Cases(): iterable
  95. {
  96. yield [
  97. '<?php
  98. class Bar
  99. {
  100. const __line__ = "foo";
  101. }
  102. namespace {
  103. echo \Bar::__line__;
  104. }',
  105. ];
  106. }
  107. }