TransformersTest.php 1.6 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. static::assertTrue($tokens->offsetExists($index));
  35. static::assertTrue($tokens[$index]->isGivenKind($expected));
  36. }
  37. }
  38. public static function provideTransformCases(): array
  39. {
  40. return [
  41. 'use trait after complex string variable' => [
  42. <<<'SOURCE'
  43. <?php
  44. class TransformTest extends TestCase
  45. {
  46. public function testSomething()
  47. {
  48. $a = 1;
  49. $this->assertSame('1', "{$a}");
  50. }
  51. use TestTrait;
  52. public function testUsingTrait()
  53. {
  54. $this->testTraitFunction();
  55. }
  56. }
  57. SOURCE
  58. ,
  59. [46 => CT::T_USE_TRAIT],
  60. ],
  61. ];
  62. }
  63. }