TokenTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. * @author Andreas Möller <am@localheinz.com>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Doctrine\Annotation\Token
  22. */
  23. final class TokenTest extends TestCase
  24. {
  25. public function testDefaults(): void
  26. {
  27. $token = new Token();
  28. self::assertSame(DocLexer::T_NONE, $token->getType());
  29. self::assertSame('', $token->getContent());
  30. self::assertSame(0, $token->getPosition());
  31. }
  32. public function testConstructorSetsValues(): void
  33. {
  34. $type = 42;
  35. $content = 'questionable';
  36. $position = 16;
  37. $token = new Token(
  38. $type,
  39. $content,
  40. $position,
  41. );
  42. self::assertSame($type, $token->getType());
  43. self::assertSame($content, $token->getContent());
  44. self::assertSame($position, $token->getPosition());
  45. }
  46. public function testCanModifyType(): void
  47. {
  48. $type = 42;
  49. $token = new Token();
  50. $token->setType($type);
  51. self::assertSame($type, $token->getType());
  52. }
  53. /**
  54. * @dataProvider provideIsTypeReturnsTrueCases
  55. *
  56. * @param int|list<int> $types
  57. */
  58. public function testIsTypeReturnsTrue(int $type, $types): void
  59. {
  60. $token = new Token();
  61. $token->setType($type);
  62. self::assertTrue($token->isType($types));
  63. }
  64. public static function provideIsTypeReturnsTrueCases(): iterable
  65. {
  66. yield 'same-value' => [
  67. 42,
  68. 42,
  69. ];
  70. yield 'array-with-value' => [
  71. 42,
  72. [
  73. 42,
  74. 9_001,
  75. ],
  76. ];
  77. }
  78. /**
  79. * @dataProvider provideIsTypeReturnsFalseCases
  80. *
  81. * @param int|list<int> $types
  82. */
  83. public function testIsTypeReturnsFalse(int $type, $types): void
  84. {
  85. $token = new Token();
  86. $token->setType($type);
  87. self::assertFalse($token->isType($types));
  88. }
  89. public static function provideIsTypeReturnsFalseCases(): iterable
  90. {
  91. yield 'different-value' => [
  92. 42,
  93. 9_001,
  94. ];
  95. yield 'array-without-value' => [
  96. 42,
  97. [
  98. 9_001,
  99. ],
  100. ];
  101. }
  102. public function testCanModifyContent(): void
  103. {
  104. $content = 'questionable';
  105. $token = new Token();
  106. $token->setContent($content);
  107. self::assertSame($content, $token->getContent());
  108. }
  109. public function testCanClearContent(): void
  110. {
  111. $content = 'questionable';
  112. $token = new Token();
  113. $token->setContent($content);
  114. $token->clear();
  115. self::assertSame('', $token->getContent());
  116. }
  117. }