PhpdocInlineTagFixerTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\Fixer\Phpdoc;
  12. use PhpCsFixer\Test\AbstractFixerTestCase;
  13. /**
  14. * Test PhpdocInlineTagFixer.
  15. *
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocInlineTagFixer
  19. */
  20. final class PhpdocInlineTagFixerTest extends AbstractFixerTestCase
  21. {
  22. /**
  23. * @param string $expected
  24. * @param null|string $input
  25. *
  26. * @dataProvider provideTestFixInlineDocCases
  27. */
  28. public function testFixInlineDoc($expected, $input = null)
  29. {
  30. $this->doTest($expected, $input);
  31. }
  32. public function provideTestFixInlineDocCases()
  33. {
  34. $cases = array(
  35. array(
  36. '<?php
  37. /**
  38. * {link} { LINK }
  39. * { test }
  40. * {@inheritdoc rire éclatant des écoliers qui décontenança®¶ñ¿}
  41. * test other comment
  42. * {@inheritdoc test} a
  43. * {@inheritdoc test} b
  44. * {@inheritdoc test} c
  45. * {@inheritdoc foo bar.} d
  46. * {@inheritdoc foo bar.} e
  47. * {@inheritdoc test} f
  48. * end comment {@inheritdoc here we are done} @spacepossum {1}
  49. */
  50. ',
  51. '<?php
  52. /**
  53. * {link} { LINK }
  54. * { test }
  55. * {@inheritDoc rire éclatant des écoliers qui décontenança®¶ñ¿ }
  56. * test other comment
  57. * @{inheritdoc test} a
  58. * {{@inheritdoc test}} b
  59. * {@ inheritdoc test} c
  60. * { @inheritdoc foo bar. } d
  61. * {@ inheritdoc foo bar. } e
  62. * @{{inheritdoc test}} f
  63. * end comment {@inheritdoc here we are done} @spacepossum {1}
  64. */
  65. ',
  66. ),
  67. );
  68. foreach (array('example', 'id', 'internal', 'inheritdoc', 'link', 'source', 'toc', 'tutorial') as $tag) {
  69. $cases[] = array(
  70. sprintf("<?php\n /**\n * {@%s}a\n */\n", $tag),
  71. sprintf("<?php\n /**\n * @{%s}a\n */\n", $tag),
  72. );
  73. $cases[] = array(
  74. sprintf("<?php\n /**\n * {@%s} b\n */\n", $tag),
  75. sprintf("<?php\n /**\n * {{@%s}} b\n */\n", $tag),
  76. );
  77. $cases[] = array(
  78. sprintf("<?php\n /**\n * c {@%s}\n */\n", $tag),
  79. sprintf("<?php\n /**\n * c @{{%s}}\n */\n", $tag),
  80. );
  81. $cases[] = array(
  82. sprintf("<?php\n /**\n * c {@%s test}\n */\n", $tag),
  83. sprintf("<?php\n /**\n * c @{{%s test}}\n */\n", $tag),
  84. );
  85. // test unbalanced { tags
  86. $cases[] = array(
  87. sprintf("<?php\n /**\n * c {@%s test}\n */\n", $tag),
  88. sprintf("<?php\n /**\n * c {@%s test}}\n */\n", $tag),
  89. );
  90. $cases[] = array(
  91. sprintf("<?php\n /**\n * c {@%s test}\n */\n", $tag),
  92. sprintf("<?php\n /**\n * c {{@%s test}\n */\n", $tag),
  93. );
  94. $cases[] = array(
  95. sprintf("<?php\n /**\n * c {@%s test}\n */\n", $tag),
  96. sprintf("<?php\n /**\n * c {@%s test}}\n */\n", $tag),
  97. );
  98. $cases[] = array(
  99. sprintf("<?php\n /**\n * c {@%s test}\n */\n", $tag),
  100. sprintf("<?php\n /**\n * c @{{%s test}}}\n */\n", $tag),
  101. );
  102. }
  103. // don't touch custom tags
  104. $tag = 'foo';
  105. $cases[] = array(
  106. sprintf("<?php\n /**\n * @{%s}a\n */\n", $tag),
  107. );
  108. $cases[] = array(
  109. sprintf("<?php\n /**\n * {{@%s}} b\n */\n", $tag),
  110. );
  111. $cases[] = array(
  112. sprintf("<?php\n /**\n * c @{{%s}}\n */\n", $tag),
  113. );
  114. // don't auto inline tags with the exception of inheritdoc
  115. foreach (array('example', 'id', 'internal', 'foo', 'link', 'source', 'toc', 'tutorial') as $tag) {
  116. $cases[] = array(
  117. sprintf("<?php\n /**\n * @%s\n */\n", $tag),
  118. );
  119. }
  120. // don't touch well formatted tags
  121. foreach (array('example', 'id', 'internal', 'inheritdoc', 'link', 'source', 'toc', 'tutorial') as $tag) {
  122. $cases[] = array(
  123. sprintf("<?php\n /**\n * {@%s}\n */\n", $tag),
  124. );
  125. }
  126. // common typos
  127. $cases[] = array(
  128. '<?php
  129. /**
  130. * Typo {@inheritdoc} {@example} {@id} {@source} {@tutorial} {links}
  131. * inheritdocs
  132. */
  133. ',
  134. '<?php
  135. /**
  136. * Typo {@inheritdocs} {@exampleS} { @ids} { @sources } {{{ @tutorials }} {links}
  137. * inheritdocs
  138. */
  139. ',
  140. );
  141. // invalid syntax
  142. $cases[] = array(
  143. '<?php
  144. /**
  145. * {@link http://www.ietf.org/rfc/rfc1035.text)
  146. */
  147. $someVar = "hello";',
  148. );
  149. return $cases;
  150. }
  151. /**
  152. * @dataProvider provideTestFixInheritDocCases
  153. */
  154. public function testFixInheritDoc($expected, $input = null)
  155. {
  156. $this->doTest($expected, $input);
  157. }
  158. public function provideTestFixInheritDocCases()
  159. {
  160. return array(
  161. array(
  162. '<?php
  163. /**
  164. * {@inheritdoc} should this be inside the tag?
  165. * {@inheritdoc}
  166. * {@inheritdoc}
  167. * {@inheritdoc}
  168. * inheritdoc
  169. */
  170. ',
  171. // missing { } test for inheritdoc
  172. '<?php
  173. /**
  174. * @inheritdoc should this be inside the tag?
  175. * @inheritdoc
  176. * @inheritdocs
  177. * {@inheritdocs}
  178. * inheritdoc
  179. */
  180. ',
  181. ),
  182. );
  183. }
  184. }