WhitespacyCommentTransformerTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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\Tokens;
  15. /**
  16. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  17. *
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\Tokenizer\Transformer\WhitespacyCommentTransformer
  21. */
  22. final class WhitespacyCommentTransformerTest extends AbstractTransformerTestCase
  23. {
  24. /**
  25. * @param array<int, array{int, string}> $expectedTokens
  26. *
  27. * @dataProvider provideProcessCases
  28. */
  29. public function testProcess(string $source, array $expectedTokens): void
  30. {
  31. $tokens = Tokens::fromCode($source);
  32. foreach ($expectedTokens as $index => $expectedToken) {
  33. $token = $tokens[$index];
  34. self::assertSame($expectedToken[1], $token->getContent());
  35. self::assertSame($expectedToken[0], $token->getId());
  36. }
  37. }
  38. /**
  39. * @return iterable<array{string, array<int, array{int, string}>}>
  40. */
  41. public static function provideProcessCases(): iterable
  42. {
  43. yield [
  44. "<?php // foo\n \$a = 1;",
  45. [
  46. 1 => [T_COMMENT, '// foo'],
  47. 2 => [T_WHITESPACE, "\n "],
  48. ],
  49. ];
  50. yield [
  51. "<?php // foo\n\n ",
  52. [
  53. 1 => [T_COMMENT, '// foo'],
  54. 2 => [T_WHITESPACE, "\n\n "],
  55. ],
  56. ];
  57. yield [
  58. "<?php // foo \r\n ",
  59. [
  60. 1 => [T_COMMENT, '// foo'],
  61. 2 => [T_WHITESPACE, " \r\n "],
  62. ],
  63. ];
  64. yield [
  65. '<?php /* foo1 */// foo2 ',
  66. [
  67. 1 => [T_COMMENT, '/* foo1 */'],
  68. 2 => [T_COMMENT, '// foo2'],
  69. ],
  70. ];
  71. }
  72. }