DocLexerTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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\Doctrine\Annotation;
  13. use PhpCsFixer\Doctrine\Annotation\DocLexer;
  14. use PhpCsFixer\Doctrine\Annotation\Token;
  15. use PhpCsFixer\Tests\TestCase;
  16. /**
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Doctrine\Annotation\DocLexer
  20. */
  21. final class DocLexerTest extends TestCase
  22. {
  23. public function testCreateFromEmptyPhpdocComment(): void
  24. {
  25. $lexer = new DocLexer();
  26. $lexer->setInput('/** @Foo("bar": 42) */');
  27. /** @var list<array{DocLexer::T_*, string, int}> */
  28. $expectedContents = [
  29. [DocLexer::T_NONE, '/', 0],
  30. [DocLexer::T_AT, '@', 4],
  31. [DocLexer::T_IDENTIFIER, 'Foo', 5],
  32. [DocLexer::T_OPEN_PARENTHESIS, '(', 8],
  33. [DocLexer::T_STRING, 'bar', 9],
  34. [DocLexer::T_COLON, ':', 14],
  35. [DocLexer::T_INTEGER, '42', 16],
  36. [DocLexer::T_CLOSE_PARENTHESIS, ')', 18],
  37. [DocLexer::T_NONE, '/', 21],
  38. ];
  39. foreach ($expectedContents as $expectedContent) {
  40. $token = $lexer->peek();
  41. self::assertInstanceOf(Token::class, $token);
  42. self::assertSame($expectedContent[0], $token->getType());
  43. self::assertSame($expectedContent[1], $token->getContent());
  44. self::assertSame($expectedContent[2], $token->getPosition());
  45. }
  46. self::assertNull($lexer->peek());
  47. }
  48. }