NoSpaceAroundDoubleColonFixerTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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\Operator;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @covers \PhpCsFixer\Fixer\Operator\NoSpaceAroundDoubleColonFixer
  16. *
  17. * @internal
  18. *
  19. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Operator\NoSpaceAroundDoubleColonFixer>
  20. */
  21. final class NoSpaceAroundDoubleColonFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFixCases
  25. */
  26. public function testFix(string $expected, string $input): void
  27. {
  28. $this->doTest($expected, $input);
  29. }
  30. /**
  31. * @return iterable<array{string, string}>
  32. */
  33. public static function provideFixCases(): iterable
  34. {
  35. yield [
  36. '<?php echo self::$a;',
  37. '<?php echo self :: $a;',
  38. ];
  39. yield [
  40. '<?php echo static::$a;',
  41. '<?php echo static ::$a;',
  42. ];
  43. yield [
  44. '<?php
  45. echo F\B::class;
  46. echo A\B:: /**/ c;
  47. echo C\B/**/::c;
  48. ',
  49. '<?php
  50. echo F\B:: class;
  51. echo A\B :: /**/ c;
  52. echo C\B/**/:: c;
  53. ',
  54. ];
  55. yield [
  56. '<?php
  57. namespace {
  58. class Foo { public const a = 1; }
  59. echo Foo::a; // Fix
  60. echo "\n".Place\Bar::$a."\n"; // Fix
  61. }
  62. namespace Somewhere\Over\The\Rainbow {
  63. class Bar {
  64. public static $a = "BAR-A:: ";
  65. public function v(?string $z = "zzz"): void
  66. {
  67. echo "\n".self::$a.$z; // Fix
  68. echo "\n".static::class; // Fix
  69. echo "\n".static # do ...
  70. :: # ... not ...
  71. $a.$z; // ... fix
  72. }
  73. }
  74. $bar = new Bar();
  75. $bar->v();
  76. }
  77. # ; echo A :: B;
  78. // ; echo A :: B;
  79. /* ; echo A :: B; */
  80. ',
  81. '<?php
  82. namespace {
  83. class Foo { public const a = 1; }
  84. echo Foo:: a; // Fix
  85. echo "\n".Place\Bar :: $a."\n"; // Fix
  86. }
  87. namespace Somewhere\Over\The\Rainbow {
  88. class Bar {
  89. public static $a = "BAR-A:: ";
  90. public function v(?string $z = "zzz"): void
  91. {
  92. echo "\n".self :: $a.$z; // Fix
  93. echo "\n".static :: class; // Fix
  94. echo "\n".static # do ...
  95. :: # ... not ...
  96. $a.$z; // ... fix
  97. }
  98. }
  99. $bar = new Bar();
  100. $bar->v();
  101. }
  102. # ; echo A :: B;
  103. // ; echo A :: B;
  104. /* ; echo A :: B; */
  105. ',
  106. ];
  107. }
  108. }