TagTest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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\DocBlock;
  13. use PhpCsFixer\DocBlock\Line;
  14. use PhpCsFixer\DocBlock\Tag;
  15. use PhpCsFixer\Tests\TestCase;
  16. /**
  17. * @author Graham Campbell <hello@gjcampbell.co.uk>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\DocBlock\Tag
  22. */
  23. final class TagTest extends TestCase
  24. {
  25. /**
  26. * @dataProvider provideNameCases
  27. */
  28. public function testName(string $expected, string $new, string $input): void
  29. {
  30. $tag = new Tag(new Line($input));
  31. static::assertSame($expected, $tag->getName());
  32. if ('other' === $expected) {
  33. $this->expectException(\RuntimeException::class);
  34. $this->expectExceptionMessage('Cannot set name on unknown tag');
  35. }
  36. $tag->setName($new);
  37. static::assertSame($new, $tag->getName());
  38. }
  39. public static function provideNameCases(): array
  40. {
  41. return [
  42. ['param', 'var', ' * @param Foo $foo'],
  43. ['return', 'type', '* @return false'],
  44. ['thRoWs', 'throws', '*@thRoWs \Exception'],
  45. ['THROWSSS', 'throws', "\t@THROWSSS\t \t RUNTIMEEEEeXCEPTION\t\t\t\t\t\t\t\n\n\n"],
  46. ['other', 'foobar', ' * @\Foo\Bar(baz = 123)'],
  47. ['expectedException', 'baz', ' * @expectedException Exception'],
  48. ['property-read', 'property-write', ' * @property-read integer $daysInMonth number of days in the given month'],
  49. ['method', 'foo', ' * @method'],
  50. ['method', 'hi', ' * @method string getString()'],
  51. ['other', 'hello', ' * @method("GET")'],
  52. ];
  53. }
  54. /**
  55. * @dataProvider provideValidCases
  56. */
  57. public function testValid(bool $expected, string $input): void
  58. {
  59. $tag = new Tag(new Line($input));
  60. static::assertSame($expected, $tag->valid());
  61. }
  62. public static function provideValidCases(): array
  63. {
  64. return [
  65. [true, ' * @param Foo $foo'],
  66. [true, '* @return false'],
  67. [true, '*@throws \Exception'],
  68. [true, ' * @method'],
  69. [true, ' * @method string getString()'],
  70. [true, ' * @property-read integer $daysInMonth number of days in the given month'],
  71. [false, ' * @method("GET")'],
  72. [false, '*@thRoWs \InvalidArgumentException'],
  73. [false, "\t@THROWSSS\t \t RUNTIMEEEEeXCEPTION\t\t\t\t\t\t\t\n\n\n"],
  74. [false, ' * @\Foo\Bar(baz = 123)'],
  75. [false, ' * @expectedException Exception'],
  76. ];
  77. }
  78. }