DocblockTest.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2017 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->assertEquals($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. return array(
  36. array('', '', array()),
  37. array(
  38. '/**
  39. * This is a docblock
  40. *
  41. * @throws \Exception with a description
  42. */',
  43. 'This is a docblock',
  44. array(
  45. 'throws' => array(array('type' => '\Exception', 'desc' => 'with a description')),
  46. ),
  47. ),
  48. array(
  49. '/**
  50. * This is a slightly longer docblock
  51. *
  52. * @param int $foo Is a Foo
  53. * @param string $bar With some sort of description
  54. * @param \ClassName $baz is cool too
  55. *
  56. * @return int At least it isn\'t a string
  57. */',
  58. 'This is a slightly longer docblock',
  59. array(
  60. 'param' => array(
  61. array('type' => 'int', 'desc' => 'Is a Foo', 'var' => '$foo'),
  62. array('type' => 'string', 'desc' => 'With some sort of description', 'var' => '$bar'),
  63. array('type' => '\ClassName', 'desc' => 'is cool too', 'var' => '$baz'),
  64. ),
  65. 'return' => array(
  66. array('type' => 'int', 'desc' => 'At least it isn\'t a string'),
  67. ),
  68. ),
  69. ),
  70. array(
  71. '/**
  72. * This is a docblock!
  73. *
  74. * It spans lines, too!
  75. *
  76. * @tagname plus a description
  77. *
  78. * @return
  79. */',
  80. "This is a docblock!\n\nIt spans lines, too!",
  81. array(
  82. 'tagname' => array('plus a description'),
  83. ),
  84. ),
  85. );
  86. }
  87. }