TransformersTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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;
  13. use PhpCsFixer\Tests\TestCase;
  14. use PhpCsFixer\Tokenizer\CT;
  15. use PhpCsFixer\Tokenizer\Tokens;
  16. /**
  17. * @author Dave van der Brugge <dmvdbrugge@gmail.com>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Tokenizer\Transformers
  22. */
  23. final class TransformersTest extends TestCase
  24. {
  25. /**
  26. * @param array<int, int> $expectedTokenKinds
  27. *
  28. * @dataProvider provideTransformCases
  29. */
  30. public function testTransform(string $input, array $expectedTokenKinds): void
  31. {
  32. $tokens = Tokens::fromCode($input);
  33. foreach ($expectedTokenKinds as $index => $expected) {
  34. self::assertTrue($tokens->offsetExists($index));
  35. self::assertTrue($tokens[$index]->isGivenKind($expected));
  36. }
  37. }
  38. /**
  39. * @return iterable<string, array{string, array<int, int>}>
  40. */
  41. public static function provideTransformCases(): iterable
  42. {
  43. yield 'use trait after complex string variable' => [
  44. <<<'SOURCE'
  45. <?php
  46. class TransformTest extends TestCase
  47. {
  48. public function testSomething()
  49. {
  50. $a = 1;
  51. $this->assertSame('1', "{$a}");
  52. }
  53. use TestTrait;
  54. public function testUsingTrait()
  55. {
  56. $this->testTraitFunction();
  57. }
  58. }
  59. SOURCE,
  60. [46 => CT::T_USE_TRAIT],
  61. ];
  62. }
  63. }