PhpdocNoUselessInheritdocFixerTest.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Fixer\Phpdoc;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @internal
  16. *
  17. * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocNoUselessInheritdocFixer
  18. *
  19. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Phpdoc\PhpdocNoUselessInheritdocFixer>
  20. */
  21. final class PhpdocNoUselessInheritdocFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFixCases
  25. */
  26. public function testFix(string $expected, ?string $input = null): void
  27. {
  28. $this->doTest($expected, $input);
  29. }
  30. /**
  31. * @return iterable<array{0: string, 1?: string, 2?: string}>
  32. */
  33. public static function provideFixCases(): iterable
  34. {
  35. yield [
  36. "<?php\n/** */class min1{}",
  37. "<?php\n/** @inheritdoc */class min1{}",
  38. ];
  39. yield [
  40. "<?php\n/** */class min1{}",
  41. "<?php\n/** @inheritDoc */class min1{}",
  42. ];
  43. yield [
  44. "<?php\nclass min2{/** */}",
  45. "<?php\nclass min2{/** @inheritdoc */}",
  46. ];
  47. yield [
  48. "<?php\nclass min2{/** */}",
  49. "<?php\nclass min2{/** @inheritDoc */}",
  50. ];
  51. yield [
  52. '<?php
  53. class A
  54. {
  55. /** */
  56. public function A(){}
  57. /**
  58. * '.'
  59. */
  60. public function B(){}
  61. /**
  62. * Descr.
  63. *
  64. * @param int $c
  65. * '.'
  66. */
  67. public function C($c){}
  68. }
  69. ',
  70. '<?php
  71. class A
  72. {
  73. /** @inheritdoc */
  74. public function A(){}
  75. /**
  76. * @inheritdoc
  77. */
  78. public function B(){}
  79. /**
  80. * Descr.
  81. *
  82. * @param int $c
  83. * @inheritdoc
  84. */
  85. public function C($c){}
  86. }
  87. ',
  88. ];
  89. yield [
  90. '<?php
  91. class B
  92. {
  93. /** */
  94. public function B(){}
  95. }
  96. ',
  97. '<?php
  98. class B
  99. {
  100. /** {@INHERITDOC} */
  101. public function B(){}
  102. }
  103. ',
  104. ];
  105. yield [
  106. '<?php
  107. /** D C */
  108. class C
  109. {
  110. }
  111. ',
  112. '<?php
  113. /** D { @INHERITDOC } C */
  114. class C
  115. {
  116. }
  117. ',
  118. ];
  119. yield [
  120. '<?php
  121. /** E */
  122. class E
  123. {
  124. }
  125. ',
  126. '<?php
  127. /** {{@Inheritdoc}} E */
  128. class E
  129. {
  130. }
  131. ',
  132. ];
  133. yield [
  134. '<?php
  135. /** F */
  136. class F
  137. {
  138. }
  139. ',
  140. '<?php
  141. /** F @inheritdoc */
  142. class F
  143. {
  144. }
  145. ',
  146. ];
  147. yield [
  148. '<?php
  149. /** */
  150. class G1{}
  151. /** */
  152. class G2{}
  153. ',
  154. '<?php
  155. /** @inheritdoc */
  156. class G1{}
  157. /** @inheritdoc */
  158. class G2{}
  159. ',
  160. ];
  161. yield [
  162. '<?php
  163. class H
  164. {
  165. /* @inheritdoc comment, not PHPDoc */
  166. public function H(){}
  167. }
  168. ',
  169. ];
  170. yield [
  171. '<?php
  172. class J extends Z
  173. {
  174. /** @inheritdoc */
  175. public function H(){}
  176. }
  177. ',
  178. ];
  179. yield [
  180. '<?php
  181. interface K extends Z
  182. {
  183. /** @inheritdoc */
  184. public function H();
  185. }
  186. ',
  187. ];
  188. yield [
  189. '<?php
  190. /** */
  191. interface K
  192. {
  193. /** */
  194. public function H();
  195. }
  196. ',
  197. '<?php
  198. /** @{inheritdoc} */
  199. interface K
  200. {
  201. /** {@Inheritdoc} */
  202. public function H();
  203. }
  204. ',
  205. ];
  206. yield [
  207. '<?php
  208. trait T
  209. {
  210. /** @inheritdoc */
  211. public function T()
  212. {
  213. }
  214. }',
  215. ];
  216. yield [
  217. '<?php
  218. class B
  219. {
  220. /** */
  221. public function falseImportFromTrait()
  222. {
  223. }
  224. }
  225. /** */
  226. class A
  227. {
  228. use T;
  229. /** @inheritdoc */
  230. public function importFromTrait()
  231. {
  232. }
  233. }
  234. ',
  235. '<?php
  236. class B
  237. {
  238. /** @inheritdoc */
  239. public function falseImportFromTrait()
  240. {
  241. }
  242. }
  243. /** @inheritdoc */
  244. class A
  245. {
  246. use T;
  247. /** @inheritdoc */
  248. public function importFromTrait()
  249. {
  250. }
  251. }
  252. ',
  253. '<?php
  254. class B
  255. {
  256. /** @inheritDoc */
  257. public function falseImportFromTrait()
  258. {
  259. }
  260. }
  261. /** @inheritDoc */
  262. class A
  263. {
  264. use T;
  265. /** @inheritDoc */
  266. public function importFromTrait()
  267. {
  268. }
  269. }
  270. ',
  271. ];
  272. yield [
  273. '<?php
  274. /** delete 1 */
  275. class A
  276. {
  277. /** delete 2 */
  278. public function B()
  279. {
  280. $a = new class implements I {
  281. /** @inheritdoc keep */
  282. public function A()
  283. {
  284. $b = new class extends D {
  285. /** @inheritdoc keep */
  286. public function C()
  287. {
  288. $d = new class() {
  289. /** delete 3 */
  290. public function D()
  291. {
  292. }
  293. };
  294. }
  295. };
  296. }
  297. };
  298. }
  299. /** delete 4 */
  300. public function B1()
  301. {
  302. $a1 = new class(){ };
  303. }
  304. /** delete 5 */
  305. public function B2()
  306. {
  307. //$a1 = new class(){ use D; };
  308. }
  309. }
  310. ',
  311. '<?php
  312. /** @inheritdoc delete 1 */
  313. class A
  314. {
  315. /** @inheritdoc delete 2 */
  316. public function B()
  317. {
  318. $a = new class implements I {
  319. /** @inheritdoc keep */
  320. public function A()
  321. {
  322. $b = new class extends D {
  323. /** @inheritdoc keep */
  324. public function C()
  325. {
  326. $d = new class() {
  327. /** @inheritdoc delete 3 */
  328. public function D()
  329. {
  330. }
  331. };
  332. }
  333. };
  334. }
  335. };
  336. }
  337. /** @inheritdoc delete 4 */
  338. public function B1()
  339. {
  340. $a1 = new class(){ };
  341. }
  342. /** @inheritdoc delete 5 */
  343. public function B2()
  344. {
  345. //$a1 = new class(){ use D; };
  346. }
  347. }
  348. ',
  349. ];
  350. }
  351. }