NoHomoglyphNamesFixerTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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\Naming;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Fred Cox <mcfedr@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Naming\NoHomoglyphNamesFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Naming\NoHomoglyphNamesFixer>
  22. */
  23. final class NoHomoglyphNamesFixerTest 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{0: string, 1?: string}>
  34. */
  35. public static function provideFixCases(): iterable
  36. {
  37. yield ['<?php $øøøøa = 1;'];
  38. yield ['<?php $name = "This should not be changed";'];
  39. yield ['<?php $name = "Это не меняется";'];
  40. yield ['<?php $name = \'Это не меняется\';'];
  41. yield ['<?php // This should not be chаnged'];
  42. yield ['<?php /* This should not be chаnged */'];
  43. yield [
  44. '<?php $name = \'wrong\';',
  45. '<?php $nаmе = \'wrong\';', // 'а' in name is a cyrillic letter
  46. ];
  47. yield [
  48. '<?php $a->name = \'wrong\';',
  49. '<?php $a->nаmе = \'wrong\';',
  50. ];
  51. yield [
  52. '<?php class A { private $name; }',
  53. '<?php class A { private $nаmе; }',
  54. ];
  55. yield [
  56. '<?php class Broken {}',
  57. '<?php class Вroken {}', // 'В' in Broken is a cyrillic letter
  58. ];
  59. yield [
  60. '<?php interface Broken {}',
  61. '<?php interface Вroken {}',
  62. ];
  63. yield [
  64. '<?php trait Broken {}',
  65. '<?php trait Вroken {}',
  66. ];
  67. yield [
  68. '<?php $a = new Broken();',
  69. '<?php $a = new Вroken();',
  70. ];
  71. yield [
  72. '<?php class A extends Broken {}',
  73. '<?php class A extends Вroken {}',
  74. ];
  75. yield [
  76. '<?php class A implements Broken {}',
  77. '<?php class A implements Вroken {}',
  78. ];
  79. yield [
  80. '<?php class A { use Broken; }',
  81. '<?php class A { use Вroken; }',
  82. ];
  83. yield [
  84. '<?php echo Broken::class;',
  85. '<?php echo Вroken::class;',
  86. ];
  87. yield [
  88. '<?php function name() {}',
  89. '<?php function nаmе() {}',
  90. ];
  91. yield [
  92. '<?php name();',
  93. '<?php nаmе();',
  94. ];
  95. yield [
  96. '<?php $first_name = "a";',
  97. '<?php $first_name = "a";', // Weird underscore symbol
  98. ];
  99. yield [
  100. '<?php class A { private string $name; }',
  101. '<?php class A { private string $nаmе; }',
  102. ];
  103. yield [
  104. '<?php class A { private ? Foo\Bar $name; }',
  105. '<?php class A { private ? Foo\Bar $nаmе; }',
  106. ];
  107. yield [
  108. '<?php class A { private array $name; }',
  109. '<?php class A { private array $nаmе; }',
  110. ];
  111. }
  112. }