TagTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\DocBlock;
  12. use PhpCsFixer\DocBlock\Line;
  13. use PhpCsFixer\DocBlock\Tag;
  14. use PhpCsFixer\Tests\TestCase;
  15. /**
  16. * @author Graham Campbell <graham@alt-three.com>
  17. *
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\DocBlock\Tag
  21. */
  22. final class TagTest extends TestCase
  23. {
  24. /**
  25. * @param string $expected
  26. * @param string $new
  27. * @param string $input
  28. *
  29. * @dataProvider provideNameCases
  30. */
  31. public function testName($expected, $new, $input)
  32. {
  33. $tag = new Tag(new Line($input));
  34. $this->assertSame($expected, $tag->getName());
  35. if ('other' === $expected) {
  36. $this->expectException(\RuntimeException::class);
  37. $this->expectExceptionMessage('Cannot set name on unknown tag');
  38. }
  39. $tag->setName($new);
  40. $this->assertSame($new, $tag->getName());
  41. }
  42. public function provideNameCases()
  43. {
  44. return [
  45. ['param', 'var', ' * @param Foo $foo'],
  46. ['return', 'type', '* @return false'],
  47. ['thRoWs', 'throws', '*@thRoWs \Exception'],
  48. ['THROWSSS', 'throws', "\t@THROWSSS\t \t RUNTIMEEEEeXCEPTION\t\t\t\t\t\t\t\n\n\n"],
  49. ['other', 'foobar', ' * @\Foo\Bar(baz = 123)'],
  50. ['expectedException', 'baz', ' * @expectedException Exception'],
  51. ['property-read', 'property-write', ' * @property-read integer $daysInMonth number of days in the given month'],
  52. ['method', 'foo', ' * @method'],
  53. ['method', 'hi', ' * @method string getString()'],
  54. ['other', 'hello', ' * @method("GET")'],
  55. ];
  56. }
  57. /**
  58. * @param bool $expected
  59. * @param string $input
  60. *
  61. * @dataProvider provideValidCases
  62. */
  63. public function testValid($expected, $input)
  64. {
  65. $tag = new Tag(new Line($input));
  66. $this->assertSame($expected, $tag->valid());
  67. }
  68. public function provideValidCases()
  69. {
  70. return [
  71. [true, ' * @param Foo $foo'],
  72. [true, '* @return false'],
  73. [true, '*@throws \Exception'],
  74. [true, ' * @method'],
  75. [true, ' * @method string getString()'],
  76. [true, ' * @property-read integer $daysInMonth number of days in the given month'],
  77. [false, ' * @method("GET")'],
  78. [false, '*@thRoWs \InvalidArgumentException'],
  79. [false, "\t@THROWSSS\t \t RUNTIMEEEEeXCEPTION\t\t\t\t\t\t\t\n\n\n"],
  80. [false, ' * @\Foo\Bar(baz = 123)'],
  81. [false, ' * @expectedException Exception'],
  82. ];
  83. }
  84. }