InterpretingDocBlocksTest.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * This file is part of phpDocumentor.
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
  9. * @license http://www.opensource.org/licenses/mit-license.php MIT
  10. * @link http://phpdoc.org
  11. */
  12. namespace phpDocumentor\Reflection;
  13. use phpDocumentor\Reflection\DocBlock\Description;
  14. use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
  15. use phpDocumentor\Reflection\DocBlock\Tag;
  16. use phpDocumentor\Reflection\DocBlock\Tags\See;
  17. /**
  18. * @coversNothing
  19. */
  20. class InterpretingDocBlocksTest extends \PHPUnit_Framework_TestCase
  21. {
  22. public function testInterpretingASimpleDocBlock()
  23. {
  24. /**
  25. * @var DocBlock $docblock
  26. * @var string $summary
  27. * @var Description $description
  28. */
  29. include(__DIR__ . '/../../examples/01-interpreting-a-simple-docblock.php');
  30. $descriptionText = <<<DESCRIPTION
  31. This is a Description. A Summary and Description are separated by either
  32. two subsequent newlines (thus a whiteline in between as can be seen in this
  33. example), or when the Summary ends with a dot (`.`) and some form of
  34. whitespace.
  35. DESCRIPTION;
  36. $this->assertInstanceOf(DocBlock::class, $docblock);
  37. $this->assertSame('This is an example of a summary.', $summary);
  38. $this->assertInstanceOf(Description::class, $description);
  39. $this->assertSame($descriptionText, $description->render());
  40. $this->assertEmpty($docblock->getTags());
  41. }
  42. public function testInterpretingTags()
  43. {
  44. /**
  45. * @var DocBlock $docblock
  46. * @var boolean $hasSeeTag
  47. * @var Tag[] $tags
  48. * @var See[] $seeTags
  49. */
  50. include(__DIR__ . '/../../examples/02-interpreting-tags.php');
  51. $this->assertTrue($hasSeeTag);
  52. $this->assertCount(1, $tags);
  53. $this->assertCount(1, $seeTags);
  54. $this->assertInstanceOf(See::class, $tags[0]);
  55. $this->assertInstanceOf(See::class, $seeTags[0]);
  56. $seeTag = $seeTags[0];
  57. $this->assertSame('\\' . StandardTagFactory::class, (string)$seeTag->getReference());
  58. $this->assertSame('', (string)$seeTag->getDescription());
  59. }
  60. public function testDescriptionsCanEscapeAtSignsAndClosingBraces()
  61. {
  62. /**
  63. * @var string $docComment
  64. * @var DocBlock $docblock
  65. * @var Description $description
  66. * @var string $receivedDocComment
  67. * @var string $foundDescription
  68. */
  69. include(__DIR__ . '/../../examples/playing-with-descriptions/02-escaping.php');
  70. $this->assertSame(<<<'DESCRIPTION'
  71. You can escape the @-sign by surrounding it with braces, for example: @. And escape a closing brace within an
  72. inline tag by adding an opening brace in front of it like this: }.
  73. Here are example texts where you can see how they could be used in a real life situation:
  74. This is a text with an {@internal inline tag where a closing brace (}) is shown}.
  75. Or an {@internal inline tag with a literal {@link} in it}.
  76. Do note that an {@internal inline tag that has an opening brace ({) does not break out}.
  77. DESCRIPTION
  78. ,
  79. $foundDescription
  80. )
  81. ;
  82. }
  83. }