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

/protected/vendor/fabpot/php-cs-fixer/Symfony/CS/Tests/DocBlock/AnnotationTest.php

https://gitlab.com/I-NOZex/quiz
PHP | 241 lines | 136 code | 43 blank | 62 comment | 0 complexity | f0bd535ee15f58754a304924e1e2b548 MD5 | raw file
  1. <?php
  2. /*
  3. * This file is part of the PHP CS utility.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\CS\Tests\DocBlock;
  11. use Symfony\CS\DocBlock\Annotation;
  12. use Symfony\CS\DocBlock\DocBlock;
  13. use Symfony\CS\DocBlock\Line;
  14. /**
  15. * @author Graham Campbell <graham@mineuk.com>
  16. */
  17. class AnnotationTest extends \PHPUnit_Framework_TestCase
  18. {
  19. /**
  20. * This represents the content an entire docblock.
  21. *
  22. * @var string
  23. */
  24. private static $sample = '/**
  25. * Test docblock.
  26. *
  27. * @param string $hello
  28. * @param bool $test Description
  29. * extends over many lines
  30. *
  31. * @param adkjbadjasbdand $asdnjkasd
  32. *
  33. * @throws \Exception asdnjkasd
  34. *
  35. * asdasdasdasdasdasdasdasd
  36. * kasdkasdkbasdasdasdjhbasdhbasjdbjasbdjhb
  37. *
  38. * @return void
  39. */';
  40. /**
  41. * This represents the content of each annotation.
  42. *
  43. * @var string[]
  44. */
  45. private static $content = array(
  46. " * @param string \$hello\n",
  47. " * @param bool \$test Description\n * extends over many lines\n",
  48. " * @param adkjbadjasbdand \$asdnjkasd\n",
  49. " * @throws \Exception asdnjkasd\n *\n * asdasdasdasdasdasdasdasd\n * kasdkasdkbasdasdasdjhbasdhbasjdbjasbdjhb\n",
  50. " * @return void\n",
  51. );
  52. /**
  53. * This represents the start indexes of each annotation.
  54. *
  55. * @var int[]
  56. */
  57. private static $start = array(3, 4, 7, 9, 14);
  58. /**
  59. * This represents the start indexes of each annotation.
  60. *
  61. * @var int[]
  62. */
  63. private static $end = array(3, 5, 7, 12, 14);
  64. /**
  65. * This represents the tag type of each annotation.
  66. *
  67. * @var int[]
  68. */
  69. private static $tags = array('param', 'param', 'param', 'throws', 'return');
  70. /**
  71. * @dataProvider provideContent
  72. */
  73. public function testGetContent($index, $content)
  74. {
  75. $doc = new DocBlock(self::$sample);
  76. $annotation = $doc->getAnnotation($index);
  77. $this->assertSame($content, $annotation->getContent());
  78. $this->assertSame($content, (string) $annotation);
  79. }
  80. public function provideContent()
  81. {
  82. $cases = array();
  83. foreach (self::$content as $index => $content) {
  84. $cases[] = array($index, $content);
  85. }
  86. return $cases;
  87. }
  88. /**
  89. * @dataProvider provideStartCases
  90. */
  91. public function testStart($index, $start)
  92. {
  93. $doc = new DocBlock(self::$sample);
  94. $annotation = $doc->getAnnotation($index);
  95. $this->assertSame($start, $annotation->getStart());
  96. }
  97. public function provideStartCases()
  98. {
  99. $cases = array();
  100. foreach (self::$start as $index => $start) {
  101. $cases[] = array($index, $start);
  102. }
  103. return $cases;
  104. }
  105. /**
  106. * @dataProvider provideEndCases
  107. */
  108. public function testEnd($index, $end)
  109. {
  110. $doc = new DocBlock(self::$sample);
  111. $annotation = $doc->getAnnotation($index);
  112. $this->assertSame($end, $annotation->getEnd());
  113. }
  114. public function provideEndCases()
  115. {
  116. $cases = array();
  117. foreach (self::$end as $index => $end) {
  118. $cases[] = array($index, $end);
  119. }
  120. return $cases;
  121. }
  122. /**
  123. * @dataProvider provideTags
  124. */
  125. public function testGetTag($index, $tag)
  126. {
  127. $doc = new DocBlock(self::$sample);
  128. $annotation = $doc->getAnnotation($index);
  129. $this->assertSame($tag, $annotation->getTag()->getName());
  130. }
  131. public function provideTags()
  132. {
  133. $cases = array();
  134. foreach (self::$tags as $index => $tag) {
  135. $cases[] = array($index, $tag);
  136. }
  137. return $cases;
  138. }
  139. /**
  140. * @dataProvider provideRemoveCases
  141. */
  142. public function testRemove($index, $start, $end)
  143. {
  144. $doc = new DocBlock(self::$sample);
  145. $annotation = $doc->getAnnotation($index);
  146. $annotation->remove();
  147. $this->assertSame('', $annotation->getContent());
  148. $this->assertSame('', $doc->getLine($start)->getContent());
  149. $this->assertSame('', $doc->getLine($end)->getContent());
  150. }
  151. public function provideRemoveCases()
  152. {
  153. $cases = array();
  154. foreach (self::$start as $index => $start) {
  155. $cases[] = array($index, $start, self::$end[$index]);
  156. }
  157. return $cases;
  158. }
  159. /**
  160. * @dataProvider provideTypesCases
  161. */
  162. public function testTypes($expected, $new, $input, $output)
  163. {
  164. $line = new Line($input);
  165. $tag = new Annotation(array($line));
  166. $this->assertSame($expected, $tag->getTypes());
  167. $tag->setTypes($new);
  168. $this->assertSame($new, $tag->getTypes());
  169. $this->assertSame($output, $line->getContent());
  170. }
  171. public function provideTypesCases()
  172. {
  173. return array(
  174. array(array('Foo', 'null'), array('Bar[]'), ' * @param Foo|null $foo', ' * @param Bar[] $foo'),
  175. array(array('false'), array('bool'), '* @return false', '* @return bool'),
  176. array(array('RUNTIMEEEEeXCEPTION'), array('Throwable'), "\t@throws\t \t RUNTIMEEEEeXCEPTION\t\t\t\t\t\t\t\n\n\n", "\t@throws\t \t Throwable\t\t\t\t\t\t\t\n\n\n"),
  177. array(array('string'), array('string', 'null'), ' * @method string getString()', ' * @method string|null getString()'),
  178. );
  179. }
  180. /**
  181. * @expectedException RuntimeException
  182. * @expectedExceptionMessage This tag does not support types
  183. */
  184. public function testGetTypesOnBadTag()
  185. {
  186. $tag = new Annotation(array(new Line(' * @deprecated since 1.2')));
  187. $tag->getTypes();
  188. }
  189. /**
  190. * @expectedException RuntimeException
  191. * @expectedExceptionMessage This tag does not support types
  192. */
  193. public function testSetTypesOnBadTag()
  194. {
  195. $tag = new Annotation(array(new Line(' * @author Chuck Norris')));
  196. $tag->setTypes(array('string'));
  197. }
  198. }