NoUnneededImportAliasFixerTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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\Import;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @internal
  16. *
  17. * @covers \PhpCsFixer\Fixer\Import\NoUnneededImportAliasFixer
  18. *
  19. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Import\NoUnneededImportAliasFixer>
  20. */
  21. final class NoUnneededImportAliasFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFixCases
  25. */
  26. public function testFix(string $expected, ?string $input = null): void
  27. {
  28. $this->doTest($expected, $input);
  29. }
  30. /**
  31. * @return iterable<array{0: string, 1?: string}>
  32. */
  33. public static function provideFixCases(): iterable
  34. {
  35. yield [
  36. '<?php use some\ns\{ClassA, ClassB, ClassC };',
  37. '<?php use some\ns\{ClassA, ClassB, ClassC as ClassC};',
  38. ];
  39. yield [
  40. '<?php
  41. use A\B\C , D\E\F as G;
  42. use const X\Y\Z as Z1, U\V\W ;
  43. use function U\V\W\FX , U\V\W\FY ;
  44. ',
  45. '<?php
  46. use A\B\C as C, D\E\F as G;
  47. use const X\Y\Z as Z1, U\V\W as W;
  48. use function U\V\W\FX as FX, U\V\W\FY as FY;
  49. ',
  50. ];
  51. yield [
  52. '<?php
  53. use F ;
  54. use X as x;
  55. use const CA ;
  56. use function FW ;
  57. ',
  58. '<?php
  59. use F as F;
  60. use X as x;
  61. use const CA as CA;
  62. use function FW as FW;
  63. ',
  64. ];
  65. yield [
  66. '<?php
  67. use /* 1 */\F ;
  68. use const \CA/* 2 */ /* 3 */;
  69. use /* 4 */ function/* 5 */ \FW /* 6 */ /* 7 */ ;
  70. ',
  71. '<?php
  72. use /* 1 */\F as F;
  73. use const \CA/* 2 */ as CA/* 3 */;
  74. use /* 4 */ function/* 5 */ \FW /* 6 */ as /* 7 */ FW;
  75. ',
  76. ];
  77. yield [
  78. '<?php
  79. use \F\B\C ;
  80. use const \X\Y\CA ;
  81. use function \U\V\FW ;
  82. ',
  83. '<?php
  84. use \F\B\C as C;
  85. use const \X\Y\CA as CA;
  86. use function \U\V\FW as FW;
  87. ',
  88. ];
  89. yield [
  90. '<?php use A\B ?> X <?php use C\D; use E\F ?>',
  91. '<?php use A\B as B ?> X <?php use C\D; use E\F as F ?>',
  92. ];
  93. yield [
  94. '<?php use A\B ?>',
  95. '<?php use A\B as B ?>',
  96. ];
  97. yield [
  98. '<?php foreach ($a as $a) {}',
  99. ];
  100. }
  101. }