TransformersTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. public static function provideTransformCases(): iterable
  39. {
  40. yield 'use trait after complex string variable' => [
  41. <<<'SOURCE'
  42. <?php
  43. class TransformTest extends TestCase
  44. {
  45. public function testSomething()
  46. {
  47. $a = 1;
  48. $this->assertSame('1', "{$a}");
  49. }
  50. use TestTrait;
  51. public function testUsingTrait()
  52. {
  53. $this->testTraitFunction();
  54. }
  55. }
  56. SOURCE
  57. ,
  58. [46 => CT::T_USE_TRAIT],
  59. ];
  60. }
  61. }