PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/vendor/phpdocumentor/reflection-docblock/tests/phpDocumentor/Reflection/DocBlock/TagTest.php

https://gitlab.com/judielsm/Handora
PHP | 313 lines | 208 code | 29 blank | 76 comment | 2 complexity | 71ee84a8a82fd5c114cd5e791bbf0e8b MD5 | raw file
  1. <?php
  2. /**
  3. * phpDocumentor Var Tag Test
  4. *
  5. * PHP version 5.3
  6. *
  7. * @author Daniel O'Connor <daniel.oconnor@gmail.com>
  8. * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
  9. * @license http://www.opensource.org/licenses/mit-license.php MIT
  10. * @link http://phpdoc.org
  11. */
  12. namespace phpDocumentor\Reflection\DocBlock;
  13. use phpDocumentor\Reflection\DocBlock;
  14. use phpDocumentor\Reflection\DocBlock\Context;
  15. /**
  16. * Test class for \phpDocumentor\Reflection\DocBlock\Tag\VarTag
  17. *
  18. * @author Daniel O'Connor <daniel.oconnor@gmail.com>
  19. * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
  20. * @license http://www.opensource.org/licenses/mit-license.php MIT
  21. * @link http://phpdoc.org
  22. */
  23. class TagTest extends \PHPUnit_Framework_TestCase
  24. {
  25. /**
  26. * @expectedException \InvalidArgumentException
  27. *
  28. * @return void
  29. */
  30. public function testInvalidTagLine()
  31. {
  32. Tag::createInstance('Invalid tag line');
  33. }
  34. /**
  35. * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
  36. *
  37. * @return void
  38. */
  39. public function testTagHandlerUnregistration()
  40. {
  41. $currentHandler = __NAMESPACE__ . '\Tag\VarTag';
  42. $tagPreUnreg = Tag::createInstance('@var mixed');
  43. $this->assertInstanceOf(
  44. $currentHandler,
  45. $tagPreUnreg
  46. );
  47. $this->assertInstanceOf(
  48. __NAMESPACE__ . '\Tag',
  49. $tagPreUnreg
  50. );
  51. Tag::registerTagHandler('var', null);
  52. $tagPostUnreg = Tag::createInstance('@var mixed');
  53. $this->assertNotInstanceOf(
  54. $currentHandler,
  55. $tagPostUnreg
  56. );
  57. $this->assertInstanceOf(
  58. __NAMESPACE__ . '\Tag',
  59. $tagPostUnreg
  60. );
  61. Tag::registerTagHandler('var', $currentHandler);
  62. }
  63. /**
  64. * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
  65. *
  66. * @return void
  67. */
  68. public function testTagHandlerCorrectRegistration()
  69. {
  70. if (0 == ini_get('allow_url_include')) {
  71. $this->markTestSkipped('"data" URIs for includes are required.');
  72. }
  73. $currentHandler = __NAMESPACE__ . '\Tag\VarTag';
  74. $tagPreReg = Tag::createInstance('@var mixed');
  75. $this->assertInstanceOf(
  76. $currentHandler,
  77. $tagPreReg
  78. );
  79. $this->assertInstanceOf(
  80. __NAMESPACE__ . '\Tag',
  81. $tagPreReg
  82. );
  83. include 'data:text/plain;base64,'. base64_encode(
  84. <<<TAG_HANDLER
  85. <?php
  86. class MyTagHandler extends \phpDocumentor\Reflection\DocBlock\Tag {}
  87. TAG_HANDLER
  88. );
  89. $this->assertTrue(Tag::registerTagHandler('var', '\MyTagHandler'));
  90. $tagPostReg = Tag::createInstance('@var mixed');
  91. $this->assertNotInstanceOf(
  92. $currentHandler,
  93. $tagPostReg
  94. );
  95. $this->assertInstanceOf(
  96. __NAMESPACE__ . '\Tag',
  97. $tagPostReg
  98. );
  99. $this->assertInstanceOf(
  100. '\MyTagHandler',
  101. $tagPostReg
  102. );
  103. $this->assertTrue(Tag::registerTagHandler('var', $currentHandler));
  104. }
  105. /**
  106. * @depends testTagHandlerCorrectRegistration
  107. * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
  108. * @covers \phpDocumentor\Reflection\DocBlock\Tag::createInstance
  109. *
  110. * @return void
  111. */
  112. public function testNamespacedTagHandlerCorrectRegistration()
  113. {
  114. $tagPreReg = Tag::createInstance('@T something');
  115. $this->assertInstanceOf(
  116. __NAMESPACE__ . '\Tag',
  117. $tagPreReg
  118. );
  119. $this->assertNotInstanceOf(
  120. '\MyTagHandler',
  121. $tagPreReg
  122. );
  123. $this->assertTrue(
  124. Tag::registerTagHandler('\MyNamespace\MyTag', '\MyTagHandler')
  125. );
  126. $tagPostReg = Tag::createInstance(
  127. '@T something',
  128. new DocBlock(
  129. '',
  130. new Context('', array('T' => '\MyNamespace\MyTag'))
  131. )
  132. );
  133. $this->assertInstanceOf(
  134. __NAMESPACE__ . '\Tag',
  135. $tagPostReg
  136. );
  137. $this->assertInstanceOf(
  138. '\MyTagHandler',
  139. $tagPostReg
  140. );
  141. $this->assertTrue(
  142. Tag::registerTagHandler('\MyNamespace\MyTag', null)
  143. );
  144. }
  145. /**
  146. * @depends testTagHandlerCorrectRegistration
  147. * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
  148. * @covers \phpDocumentor\Reflection\DocBlock\Tag::createInstance
  149. *
  150. * @return void
  151. */
  152. public function testNamespacedTagHandlerIncorrectRegistration()
  153. {
  154. $tagPreReg = Tag::createInstance('@T something');
  155. $this->assertInstanceOf(
  156. __NAMESPACE__ . '\Tag',
  157. $tagPreReg
  158. );
  159. $this->assertNotInstanceOf(
  160. '\MyTagHandler',
  161. $tagPreReg
  162. );
  163. $this->assertFalse(
  164. Tag::registerTagHandler('MyNamespace\MyTag', '\MyTagHandler')
  165. );
  166. $tagPostReg = Tag::createInstance(
  167. '@T something',
  168. new DocBlock(
  169. '',
  170. new Context('', array('T' => '\MyNamespace\MyTag'))
  171. )
  172. );
  173. $this->assertInstanceOf(
  174. __NAMESPACE__ . '\Tag',
  175. $tagPostReg
  176. );
  177. $this->assertNotInstanceOf(
  178. '\MyTagHandler',
  179. $tagPostReg
  180. );
  181. }
  182. /**
  183. * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
  184. *
  185. * @return void
  186. */
  187. public function testNonExistentTagHandlerRegistration()
  188. {
  189. $currentHandler = __NAMESPACE__ . '\Tag\VarTag';
  190. $tagPreReg = Tag::createInstance('@var mixed');
  191. $this->assertInstanceOf(
  192. $currentHandler,
  193. $tagPreReg
  194. );
  195. $this->assertInstanceOf(
  196. __NAMESPACE__ . '\Tag',
  197. $tagPreReg
  198. );
  199. $this->assertFalse(Tag::registerTagHandler('var', 'Non existent'));
  200. $tagPostReg = Tag::createInstance('@var mixed');
  201. $this->assertInstanceOf(
  202. $currentHandler,
  203. $tagPostReg
  204. );
  205. $this->assertInstanceOf(
  206. __NAMESPACE__ . '\Tag',
  207. $tagPostReg
  208. );
  209. }
  210. /**
  211. * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
  212. *
  213. * @return void
  214. */
  215. public function testIncompatibleTagHandlerRegistration()
  216. {
  217. $currentHandler = __NAMESPACE__ . '\Tag\VarTag';
  218. $tagPreReg = Tag::createInstance('@var mixed');
  219. $this->assertInstanceOf(
  220. $currentHandler,
  221. $tagPreReg
  222. );
  223. $this->assertInstanceOf(
  224. __NAMESPACE__ . '\Tag',
  225. $tagPreReg
  226. );
  227. $this->assertFalse(
  228. Tag::registerTagHandler('var', __NAMESPACE__ . '\TagTest')
  229. );
  230. $tagPostReg = Tag::createInstance('@var mixed');
  231. $this->assertInstanceOf(
  232. $currentHandler,
  233. $tagPostReg
  234. );
  235. $this->assertInstanceOf(
  236. __NAMESPACE__ . '\Tag',
  237. $tagPostReg
  238. );
  239. }
  240. /**
  241. * Test that the \phpDocumentor\Reflection\DocBlock\Tag\VarTag can
  242. * understand the @var doc block.
  243. *
  244. * @param string $type
  245. * @param string $content
  246. * @param string $exDescription
  247. *
  248. * @covers \phpDocumentor\Reflection\DocBlock\Tag
  249. * @dataProvider provideDataForConstuctor
  250. *
  251. * @return void
  252. */
  253. public function testConstructorParesInputsIntoCorrectFields(
  254. $type,
  255. $content,
  256. $exDescription
  257. ) {
  258. $tag = new Tag($type, $content);
  259. $this->assertEquals($type, $tag->getName());
  260. $this->assertEquals($content, $tag->getContent());
  261. $this->assertEquals($exDescription, $tag->getDescription());
  262. }
  263. /**
  264. * Data provider for testConstructorParesInputsIntoCorrectFields
  265. *
  266. * @return array
  267. */
  268. public function provideDataForConstuctor()
  269. {
  270. // $type, $content, $exDescription
  271. return array(
  272. array(
  273. 'unknown',
  274. 'some content',
  275. 'some content',
  276. ),
  277. array(
  278. 'unknown',
  279. '',
  280. '',
  281. )
  282. );
  283. }
  284. }