SerializerTest.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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\DocBlock;
  13. use Mockery as m;
  14. use phpDocumentor\Reflection\DocBlock;
  15. /**
  16. * @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Serializer
  17. * @covers ::<private>
  18. */
  19. class SerializerTest extends \PHPUnit_Framework_TestCase
  20. {
  21. /**
  22. * @covers ::__construct
  23. * @covers ::getDocComment
  24. * @uses phpDocumentor\Reflection\DocBlock\Description
  25. * @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
  26. * @uses phpDocumentor\Reflection\DocBlock
  27. * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
  28. * @uses phpDocumentor\Reflection\DocBlock\Tags\Generic
  29. */
  30. public function testReconstructsADocCommentFromADocBlock()
  31. {
  32. $expected = <<<'DOCCOMMENT'
  33. /**
  34. * This is a summary
  35. *
  36. * This is a description
  37. *
  38. * @unknown-tag Test description for the unknown tag
  39. */
  40. DOCCOMMENT;
  41. $fixture = new Serializer();
  42. $docBlock = new DocBlock(
  43. 'This is a summary',
  44. new Description('This is a description'),
  45. [
  46. new DocBlock\Tags\Generic('unknown-tag', new Description('Test description for the unknown tag'))
  47. ]
  48. );
  49. $this->assertSame($expected, $fixture->getDocComment($docBlock));
  50. }
  51. /**
  52. * @covers ::__construct
  53. * @covers ::getDocComment
  54. * @uses phpDocumentor\Reflection\DocBlock\Description
  55. * @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
  56. * @uses phpDocumentor\Reflection\DocBlock
  57. * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
  58. * @uses phpDocumentor\Reflection\DocBlock\Tags\Generic
  59. */
  60. public function testAddPrefixToDocBlock()
  61. {
  62. $expected = <<<'DOCCOMMENT'
  63. aa/**
  64. aa * This is a summary
  65. aa *
  66. aa * This is a description
  67. aa *
  68. aa * @unknown-tag Test description for the unknown tag
  69. aa */
  70. DOCCOMMENT;
  71. $fixture = new Serializer(2, 'a');
  72. $docBlock = new DocBlock(
  73. 'This is a summary',
  74. new Description('This is a description'),
  75. [
  76. new DocBlock\Tags\Generic('unknown-tag', new Description('Test description for the unknown tag'))
  77. ]
  78. );
  79. $this->assertSame($expected, $fixture->getDocComment($docBlock));
  80. }
  81. /**
  82. * @covers ::__construct
  83. * @covers ::getDocComment
  84. * @uses phpDocumentor\Reflection\DocBlock\Description
  85. * @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
  86. * @uses phpDocumentor\Reflection\DocBlock
  87. * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
  88. * @uses phpDocumentor\Reflection\DocBlock\Tags\Generic
  89. */
  90. public function testAddPrefixToDocBlockExceptFirstLine()
  91. {
  92. $expected = <<<'DOCCOMMENT'
  93. /**
  94. aa * This is a summary
  95. aa *
  96. aa * This is a description
  97. aa *
  98. aa * @unknown-tag Test description for the unknown tag
  99. aa */
  100. DOCCOMMENT;
  101. $fixture = new Serializer(2, 'a', false);
  102. $docBlock = new DocBlock(
  103. 'This is a summary',
  104. new Description('This is a description'),
  105. [
  106. new DocBlock\Tags\Generic('unknown-tag', new Description('Test description for the unknown tag'))
  107. ]
  108. );
  109. $this->assertSame($expected, $fixture->getDocComment($docBlock));
  110. }
  111. /**
  112. * @covers ::__construct
  113. * @covers ::getDocComment
  114. * @uses phpDocumentor\Reflection\DocBlock\Description
  115. * @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
  116. * @uses phpDocumentor\Reflection\DocBlock
  117. * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
  118. * @uses phpDocumentor\Reflection\DocBlock\Tags\Generic
  119. */
  120. public function testWordwrapsAroundTheGivenAmountOfCharacters()
  121. {
  122. $expected = <<<'DOCCOMMENT'
  123. /**
  124. * This is a
  125. * summary
  126. *
  127. * This is a
  128. * description
  129. *
  130. * @unknown-tag
  131. * Test
  132. * description
  133. * for the
  134. * unknown tag
  135. */
  136. DOCCOMMENT;
  137. $fixture = new Serializer(0, '', true, 15);
  138. $docBlock = new DocBlock(
  139. 'This is a summary',
  140. new Description('This is a description'),
  141. [
  142. new DocBlock\Tags\Generic('unknown-tag', new Description('Test description for the unknown tag'))
  143. ]
  144. );
  145. $this->assertSame($expected, $fixture->getDocComment($docBlock));
  146. }
  147. /**
  148. * @covers ::__construct
  149. * @expectedException \InvalidArgumentException
  150. */
  151. public function testInitializationFailsIfIndentIsNotAnInteger()
  152. {
  153. new Serializer([]);
  154. }
  155. /**
  156. * @covers ::__construct
  157. * @expectedException \InvalidArgumentException
  158. */
  159. public function testInitializationFailsIfIndentStringIsNotAString()
  160. {
  161. new Serializer(0, []);
  162. }
  163. /**
  164. * @covers ::__construct
  165. * @expectedException \InvalidArgumentException
  166. */
  167. public function testInitializationFailsIfIndentFirstLineIsNotABoolean()
  168. {
  169. new Serializer(0, '', []);
  170. }
  171. /**
  172. * @covers ::__construct
  173. * @expectedException \InvalidArgumentException
  174. */
  175. public function testInitializationFailsIfLineLengthIsNotNullNorAnInteger()
  176. {
  177. new Serializer(0, '', false, []);
  178. }
  179. }