TransformersTest.php 1.5 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. * @dataProvider provideTransformCases
  27. */
  28. public function testTransform(string $input, array $expectedTokenKinds): void
  29. {
  30. $tokens = Tokens::fromCode($input);
  31. foreach ($expectedTokenKinds as $index => $expected) {
  32. static::assertTrue($tokens->offsetExists($index));
  33. static::assertTrue($tokens[$index]->isGivenKind($expected));
  34. }
  35. }
  36. public function provideTransformCases(): array
  37. {
  38. return [
  39. 'use trait after complex string variable' => [
  40. <<<'SOURCE'
  41. <?php
  42. class TransformTest extends TestCase
  43. {
  44. public function testSomething()
  45. {
  46. $a = 1;
  47. $this->assertSame('1', "{$a}");
  48. }
  49. use TestTrait;
  50. public function testUsingTrait()
  51. {
  52. $this->testTraitFunction();
  53. }
  54. }
  55. SOURCE
  56. ,
  57. [46 => CT::T_USE_TRAIT],
  58. ],
  59. ];
  60. }
  61. }