ImportTransformerTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\Tokenizer\Transformer;
  13. use PhpCsFixer\Tests\Test\AbstractTransformerTestCase;
  14. use PhpCsFixer\Tokenizer\CT;
  15. /**
  16. * @author Gregor Harlan <gharlan@web.de>
  17. *
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\Tokenizer\Transformer\ImportTransformer
  21. */
  22. final class ImportTransformerTest extends AbstractTransformerTestCase
  23. {
  24. /**
  25. * @dataProvider provideProcessCases
  26. */
  27. public function testProcess(string $source, array $expectedTokens = []): void
  28. {
  29. $this->doTest(
  30. $source,
  31. $expectedTokens,
  32. [
  33. T_CONST,
  34. CT::T_CONST_IMPORT,
  35. T_FUNCTION,
  36. CT::T_FUNCTION_IMPORT,
  37. ]
  38. );
  39. }
  40. public function provideProcessCases(): array
  41. {
  42. return [
  43. [
  44. '<?php const FOO = 1;',
  45. [
  46. 1 => T_CONST,
  47. ],
  48. ],
  49. [
  50. '<?php use Foo; const FOO = 1;',
  51. [
  52. 6 => T_CONST,
  53. ],
  54. ],
  55. [
  56. '<?php class Foo { const BAR = 1; }',
  57. [
  58. 7 => T_CONST,
  59. ],
  60. ],
  61. [
  62. '<?php use const Foo\\BAR;',
  63. [
  64. 3 => CT::T_CONST_IMPORT,
  65. ],
  66. ],
  67. [
  68. '<?php function foo() {}',
  69. [
  70. 1 => T_FUNCTION,
  71. ],
  72. ],
  73. [
  74. '<?php $a = function () {};',
  75. [
  76. 5 => T_FUNCTION,
  77. ],
  78. ],
  79. [
  80. '<?php class Foo { function foo() {} }',
  81. [
  82. 7 => T_FUNCTION,
  83. ],
  84. ],
  85. [
  86. '<?php use function Foo\\bar;',
  87. [
  88. 3 => CT::T_FUNCTION_IMPORT,
  89. ],
  90. ],
  91. ];
  92. }
  93. }