DocblockTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2018 Justin Hileman
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Psy\Test\Util;
  11. use Psy\Util\Docblock;
  12. class DocblockTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @dataProvider comments
  16. */
  17. public function testDocblockParsing($comment, $body, $tags)
  18. {
  19. $reflector = $this
  20. ->getMockBuilder('ReflectionClass')
  21. ->disableOriginalConstructor()
  22. ->getMock();
  23. $reflector->expects($this->once())
  24. ->method('getDocComment')
  25. ->will($this->returnValue($comment));
  26. $docblock = new Docblock($reflector);
  27. $this->assertSame($body, $docblock->desc);
  28. foreach ($tags as $tag => $value) {
  29. $this->assertTrue($docblock->hasTag($tag));
  30. $this->assertEquals($value, $docblock->tag($tag));
  31. }
  32. }
  33. public function comments()
  34. {
  35. if (\defined('HHVM_VERSION')) {
  36. $this->markTestSkipped('We have issues with PHPUnit mocks on HHVM.');
  37. }
  38. return [
  39. ['', '', []],
  40. [
  41. '/**
  42. * This is a docblock
  43. *
  44. * @throws \Exception with a description
  45. */',
  46. 'This is a docblock',
  47. [
  48. 'throws' => [['type' => '\Exception', 'desc' => 'with a description']],
  49. ],
  50. ],
  51. [
  52. '/**
  53. * This is a slightly longer docblock
  54. *
  55. * @param int $foo Is a Foo
  56. * @param string $bar With some sort of description
  57. * @param \ClassName $baz is cool too
  58. *
  59. * @return int At least it isn\'t a string
  60. */',
  61. 'This is a slightly longer docblock',
  62. [
  63. 'param' => [
  64. ['type' => 'int', 'desc' => 'Is a Foo', 'var' => '$foo'],
  65. ['type' => 'string', 'desc' => 'With some sort of description', 'var' => '$bar'],
  66. ['type' => '\ClassName', 'desc' => 'is cool too', 'var' => '$baz'],
  67. ],
  68. 'return' => [
  69. ['type' => 'int', 'desc' => 'At least it isn\'t a string'],
  70. ],
  71. ],
  72. ],
  73. [
  74. '/**
  75. * This is a docblock!
  76. *
  77. * It spans lines, too!
  78. *
  79. * @tagname plus a description
  80. *
  81. * @return
  82. */',
  83. "This is a docblock!\n\nIt spans lines, too!",
  84. [
  85. 'tagname' => ['plus a description'],
  86. ],
  87. ],
  88. ];
  89. }
  90. }