PhpdocOrderByValueFixerTest.php 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462
  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\ConfigurationException\InvalidFixerConfigurationException;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Filippo Tessarotto <zoeslam@gmail.com>
  16. * @author Andreas Möller <am@localheinz.com>
  17. *
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocOrderByValueFixer
  21. */
  22. final class PhpdocOrderByValueFixerTest extends AbstractFixerTestCase
  23. {
  24. /**
  25. * @dataProvider provideInvalidAnnotationCases
  26. *
  27. * @param mixed $annotation
  28. */
  29. public function testConfigureRejectsInvalidControlStatement($annotation)
  30. {
  31. $this->expectException(InvalidFixerConfigurationException::class);
  32. $this->fixer->configure([
  33. 'annotations' => [
  34. $annotation,
  35. ],
  36. ]);
  37. }
  38. /**
  39. * @return array
  40. */
  41. public function provideInvalidAnnotationCases()
  42. {
  43. return [
  44. 'null' => [null],
  45. 'false' => [false],
  46. 'true' => [true],
  47. 'int' => [0],
  48. 'float' => [3.14],
  49. 'array' => [[]],
  50. 'object' => [new \stdClass()],
  51. 'unknown' => ['foo'],
  52. ];
  53. }
  54. /**
  55. * @param string $expected
  56. * @param null|string $input
  57. *
  58. * @dataProvider provideFixWithCoversCases
  59. */
  60. public function testFixWithDefaultConfiguration($expected, $input = null)
  61. {
  62. $this->doTest($expected, $input);
  63. }
  64. /**
  65. * @param string $expected
  66. * @param null|string $input
  67. *
  68. * @dataProvider provideFixWithAuthorCases
  69. */
  70. public function testFixWithAuthor($expected, $input = null)
  71. {
  72. $this->fixer->configure([
  73. 'annotations' => [
  74. 'author',
  75. ],
  76. ]);
  77. $this->doTest($expected, $input);
  78. }
  79. public function provideFixWithAuthorCases()
  80. {
  81. return [
  82. 'skip on 1 or 0 occurrences' => [
  83. '<?php
  84. class FooTest extends \PHPUnit_Framework_TestCase {
  85. /**
  86. * @author Bob
  87. * @params bool $bool
  88. * @return void
  89. */
  90. public function testMe() {}
  91. /**
  92. * @params bool $bool
  93. * @return void
  94. */
  95. public function testMe2() {}
  96. }
  97. ',
  98. ],
  99. 'base case' => [
  100. '<?php
  101. /**
  102. * @author Alice
  103. * @author Bob
  104. */
  105. class FooTest extends \PHPUnit_Framework_TestCase {}
  106. ',
  107. '<?php
  108. /**
  109. * @author Bob
  110. * @author Alice
  111. */
  112. class FooTest extends \PHPUnit_Framework_TestCase {}
  113. ',
  114. ],
  115. 'preserve positions if other docblock parts are present' => [
  116. '<?php
  117. /**
  118. * Comment 1
  119. * @author Alice
  120. * Comment 3
  121. * @author Bob
  122. * Comment 2
  123. */
  124. class FooTest extends \PHPUnit_Framework_TestCase {}
  125. ',
  126. '<?php
  127. /**
  128. * Comment 1
  129. * @author Bob
  130. * Comment 2
  131. * @author Alice
  132. * Comment 3
  133. */
  134. class FooTest extends \PHPUnit_Framework_TestCase {}
  135. ',
  136. ],
  137. 'case-insensitive' => [
  138. '<?php
  139. /**
  140. * @author Alice
  141. * @author chris
  142. * @author Daniel
  143. * @author Erna
  144. */
  145. class FooTest extends \PHPUnit_Framework_TestCase {}
  146. ',
  147. '<?php
  148. /**
  149. * @author Alice
  150. * @author Erna
  151. * @author chris
  152. * @author Daniel
  153. */
  154. class FooTest extends \PHPUnit_Framework_TestCase {}
  155. ',
  156. ],
  157. 'data provider' => [
  158. '<?php
  159. class FooTest extends \PHPUnit_Framework_TestCase
  160. {
  161. /**
  162. * @author Alice
  163. * @dataProvider provide
  164. * @author Bob
  165. */
  166. public function testMe() {}
  167. }
  168. ',
  169. '<?php
  170. class FooTest extends \PHPUnit_Framework_TestCase
  171. {
  172. /**
  173. * @author Bob
  174. * @dataProvider provide
  175. * @author Alice
  176. */
  177. public function testMe() {}
  178. }
  179. ',
  180. ],
  181. ];
  182. }
  183. /**
  184. * @param string $expected
  185. * @param null|string $input
  186. *
  187. * @dataProvider provideFixWithCoversCases
  188. */
  189. public function testFixWithCovers($expected, $input = null)
  190. {
  191. $this->fixer->configure([
  192. 'annotations' => [
  193. 'covers',
  194. ],
  195. ]);
  196. $this->doTest($expected, $input);
  197. }
  198. public function provideFixWithCoversCases()
  199. {
  200. return [
  201. 'skip on 1 or 0 occurrences' => [
  202. '<?php
  203. class FooTest extends \PHPUnit_Framework_TestCase {
  204. /**
  205. * @covers Foo
  206. * @params bool $bool
  207. * @return void
  208. */
  209. public function testMe() {}
  210. /**
  211. * @params bool $bool
  212. * @return void
  213. */
  214. public function testMe2() {}
  215. }
  216. ',
  217. ],
  218. 'base case' => [
  219. '<?php
  220. /**
  221. * @covers Bar
  222. * @covers Foo
  223. */
  224. class FooTest extends \PHPUnit_Framework_TestCase {}
  225. ',
  226. '<?php
  227. /**
  228. * @covers Foo
  229. * @covers Bar
  230. */
  231. class FooTest extends \PHPUnit_Framework_TestCase {}
  232. ',
  233. ],
  234. 'preserve positions if other docblock parts are present' => [
  235. '<?php
  236. /**
  237. * Comment 1
  238. * @covers Bar
  239. * Comment 3
  240. * @covers Foo
  241. * Comment 2
  242. */
  243. class FooTest extends \PHPUnit_Framework_TestCase {}
  244. ',
  245. '<?php
  246. /**
  247. * Comment 1
  248. * @covers Foo
  249. * Comment 2
  250. * @covers Bar
  251. * Comment 3
  252. */
  253. class FooTest extends \PHPUnit_Framework_TestCase {}
  254. ',
  255. ],
  256. 'case-insensitive' => [
  257. '<?php
  258. /**
  259. * @covers A
  260. * @covers c
  261. * @covers D
  262. * @covers E
  263. */
  264. class FooTest extends \PHPUnit_Framework_TestCase {}
  265. ',
  266. '<?php
  267. /**
  268. * @covers A
  269. * @covers E
  270. * @covers c
  271. * @covers D
  272. */
  273. class FooTest extends \PHPUnit_Framework_TestCase {}
  274. ',
  275. ],
  276. 'data provider' => [
  277. '<?php
  278. class FooTest extends \PHPUnit_Framework_TestCase
  279. {
  280. /**
  281. * @covers Bar
  282. * @dataProvider provide
  283. * @covers Foo
  284. */
  285. public function testMe() {}
  286. }
  287. ',
  288. '<?php
  289. class FooTest extends \PHPUnit_Framework_TestCase
  290. {
  291. /**
  292. * @covers Foo
  293. * @dataProvider provide
  294. * @covers Bar
  295. */
  296. public function testMe() {}
  297. }
  298. ',
  299. ],
  300. ];
  301. }
  302. /**
  303. * @param string $expected
  304. * @param null|string $input
  305. *
  306. * @dataProvider provideFixWithCoversNothingCases
  307. */
  308. public function testFixWithCoversNothing($expected, $input = null)
  309. {
  310. $this->fixer->configure([
  311. 'annotations' => [
  312. 'coversNothing',
  313. ],
  314. ]);
  315. $this->doTest($expected, $input);
  316. }
  317. public function provideFixWithCoversNothingCases()
  318. {
  319. return [
  320. 'skip on 1 or 0 occurrences' => [
  321. '<?php
  322. class FooTest extends \PHPUnit_Framework_TestCase {
  323. /**
  324. * @coversNothing Foo
  325. * @params bool $bool
  326. * @return void
  327. */
  328. public function testMe() {}
  329. /**
  330. * @params bool $bool
  331. * @return void
  332. */
  333. public function testMe2() {}
  334. }
  335. ',
  336. ],
  337. 'base case' => [
  338. '<?php
  339. /**
  340. * @coversNothing Bar
  341. * @coversNothing Foo
  342. */
  343. class FooTest extends \PHPUnit_Framework_TestCase {}
  344. ',
  345. '<?php
  346. /**
  347. * @coversNothing Foo
  348. * @coversNothing Bar
  349. */
  350. class FooTest extends \PHPUnit_Framework_TestCase {}
  351. ',
  352. ],
  353. 'preserve positions if other docblock parts are present' => [
  354. '<?php
  355. /**
  356. * Comment 1
  357. * @coversNothing Bar
  358. * Comment 3
  359. * @coversNothing Foo
  360. * Comment 2
  361. */
  362. class FooTest extends \PHPUnit_Framework_TestCase {}
  363. ',
  364. '<?php
  365. /**
  366. * Comment 1
  367. * @coversNothing Foo
  368. * Comment 2
  369. * @coversNothing Bar
  370. * Comment 3
  371. */
  372. class FooTest extends \PHPUnit_Framework_TestCase {}
  373. ',
  374. ],
  375. 'case-insensitive' => [
  376. '<?php
  377. /**
  378. * @coversNothing A
  379. * @coversNothing c
  380. * @coversNothing D
  381. * @coversNothing E
  382. */
  383. class FooTest extends \PHPUnit_Framework_TestCase {}
  384. ',
  385. '<?php
  386. /**
  387. * @coversNothing A
  388. * @coversNothing E
  389. * @coversNothing c
  390. * @coversNothing D
  391. */
  392. class FooTest extends \PHPUnit_Framework_TestCase {}
  393. ',
  394. ],
  395. 'data provider' => [
  396. '<?php
  397. class FooTest extends \PHPUnit_Framework_TestCase
  398. {
  399. /**
  400. * @coversNothing Bar
  401. * @dataProvider provide
  402. * @coversNothing Foo
  403. */
  404. public function testMe() {}
  405. }
  406. ',
  407. '<?php
  408. class FooTest extends \PHPUnit_Framework_TestCase
  409. {
  410. /**
  411. * @coversNothing Foo
  412. * @dataProvider provide
  413. * @coversNothing Bar
  414. */
  415. public function testMe() {}
  416. }
  417. ',
  418. ],
  419. ];
  420. }
  421. /**
  422. * @param string $expected
  423. * @param null|string $input
  424. *
  425. * @dataProvider provideFixWithDataProviderCases
  426. */
  427. public function testFixWithDataProvider($expected, $input = null)
  428. {
  429. $this->fixer->configure([
  430. 'annotations' => [
  431. 'dataProvider',
  432. ],
  433. ]);
  434. $this->doTest($expected, $input);
  435. }
  436. public function provideFixWithDataProviderCases()
  437. {
  438. return [
  439. 'skip on 1 or 0 occurrences' => [
  440. '<?php
  441. class FooTest extends \PHPUnit_Framework_TestCase {
  442. /**
  443. * @dataProvider Foo::provideData()
  444. * @params bool $bool
  445. * @return void
  446. */
  447. public function testMe() {}
  448. /**
  449. * @params bool $bool
  450. * @return void
  451. */
  452. public function testMe2() {}
  453. }
  454. ',
  455. ],
  456. 'base case' => [
  457. '<?php
  458. /**
  459. * @dataProvider Bar::provideData()
  460. * @dataProvider Foo::provideData()
  461. */
  462. class FooTest extends \PHPUnit_Framework_TestCase {}
  463. ',
  464. '<?php
  465. /**
  466. * @dataProvider Foo::provideData()
  467. * @dataProvider Bar::provideData()
  468. */
  469. class FooTest extends \PHPUnit_Framework_TestCase {}
  470. ',
  471. ],
  472. 'preserve positions if other docblock parts are present' => [
  473. '<?php
  474. /**
  475. * Comment 1
  476. * @dataProvider Bar::provideData()
  477. * Comment 3
  478. * @dataProvider Foo::provideData()
  479. * Comment 2
  480. */
  481. class FooTest extends \PHPUnit_Framework_TestCase {}
  482. ',
  483. '<?php
  484. /**
  485. * Comment 1
  486. * @dataProvider Foo::provideData()
  487. * Comment 2
  488. * @dataProvider Bar::provideData()
  489. * Comment 3
  490. */
  491. class FooTest extends \PHPUnit_Framework_TestCase {}
  492. ',
  493. ],
  494. 'case-insensitive' => [
  495. '<?php
  496. /**
  497. * @dataProvider A::provideData()
  498. * @dataProvider c::provideData()
  499. * @dataProvider D::provideData()
  500. * @dataProvider E::provideData()
  501. */
  502. class FooTest extends \PHPUnit_Framework_TestCase {}
  503. ',
  504. '<?php
  505. /**
  506. * @dataProvider A::provideData()
  507. * @dataProvider E::provideData()
  508. * @dataProvider c::provideData()
  509. * @dataProvider D::provideData()
  510. */
  511. class FooTest extends \PHPUnit_Framework_TestCase {}
  512. ',
  513. ],
  514. 'data provider' => [
  515. '<?php
  516. class FooTest extends \PHPUnit_Framework_TestCase
  517. {
  518. /**
  519. * @dataProvider Bar::provideData()
  520. * @dataProvider dataProvider
  521. * @dataProvider Foo::provideData()
  522. */
  523. public function testMe() {}
  524. }
  525. ',
  526. '<?php
  527. class FooTest extends \PHPUnit_Framework_TestCase
  528. {
  529. /**
  530. * @dataProvider Foo::provideData()
  531. * @dataProvider dataProvider
  532. * @dataProvider Bar::provideData()
  533. */
  534. public function testMe() {}
  535. }
  536. ',
  537. ],
  538. ];
  539. }
  540. /**
  541. * @param string $expected
  542. * @param null|string $input
  543. *
  544. * @dataProvider provideFixWithDependsCases
  545. */
  546. public function testFixWithDepends($expected, $input = null)
  547. {
  548. $this->fixer->configure([
  549. 'annotations' => [
  550. 'depends',
  551. ],
  552. ]);
  553. $this->doTest($expected, $input);
  554. }
  555. public function provideFixWithDependsCases()
  556. {
  557. return [
  558. 'skip on 1 or 0 occurrences' => [
  559. '<?php
  560. class FooTest extends \PHPUnit_Framework_TestCase {
  561. /**
  562. * @depends testFoo
  563. * @params bool $bool
  564. * @return void
  565. */
  566. public function testMe() {}
  567. /**
  568. * @params bool $bool
  569. * @return void
  570. */
  571. public function testMe2() {}
  572. }
  573. ',
  574. ],
  575. 'base case' => [
  576. '<?php
  577. /**
  578. * @depends testBar
  579. * @depends testFoo
  580. */
  581. class FooTest extends \PHPUnit_Framework_TestCase {}
  582. ',
  583. '<?php
  584. /**
  585. * @depends testFoo
  586. * @depends testBar
  587. */
  588. class FooTest extends \PHPUnit_Framework_TestCase {}
  589. ',
  590. ],
  591. 'preserve positions if other docblock parts are present' => [
  592. '<?php
  593. /**
  594. * Comment 1
  595. * @depends testBar
  596. * Comment 3
  597. * @depends testFoo
  598. * Comment 2
  599. */
  600. class FooTest extends \PHPUnit_Framework_TestCase {}
  601. ',
  602. '<?php
  603. /**
  604. * Comment 1
  605. * @depends testFoo
  606. * Comment 2
  607. * @depends testBar
  608. * Comment 3
  609. */
  610. class FooTest extends \PHPUnit_Framework_TestCase {}
  611. ',
  612. ],
  613. 'case-insensitive' => [
  614. '<?php
  615. /**
  616. * @depends testA
  617. * @depends testc
  618. * @depends testD
  619. * @depends testE
  620. */
  621. class FooTest extends \PHPUnit_Framework_TestCase {}
  622. ',
  623. '<?php
  624. /**
  625. * @depends testA
  626. * @depends testE
  627. * @depends testc
  628. * @depends testD
  629. */
  630. class FooTest extends \PHPUnit_Framework_TestCase {}
  631. ',
  632. ],
  633. 'data provider' => [
  634. '<?php
  635. class FooTest extends \PHPUnit_Framework_TestCase
  636. {
  637. /**
  638. * @depends testBar
  639. * @dataProvider provide
  640. * @depends testFoo
  641. */
  642. public function testMe() {}
  643. }
  644. ',
  645. '<?php
  646. class FooTest extends \PHPUnit_Framework_TestCase
  647. {
  648. /**
  649. * @depends testFoo
  650. * @dataProvider provide
  651. * @depends testBar
  652. */
  653. public function testMe() {}
  654. }
  655. ',
  656. ],
  657. ];
  658. }
  659. /**
  660. * @param string $expected
  661. * @param null|string $input
  662. *
  663. * @dataProvider provideFixWithGroupCases
  664. */
  665. public function testFixWithGroup($expected, $input = null)
  666. {
  667. $this->fixer->configure([
  668. 'annotations' => [
  669. 'group',
  670. ],
  671. ]);
  672. $this->doTest($expected, $input);
  673. }
  674. public function provideFixWithGroupCases()
  675. {
  676. return [
  677. 'skip on 1 or 0 occurrences' => [
  678. '<?php
  679. class FooTest extends \PHPUnit_Framework_TestCase {
  680. /**
  681. * @group slow
  682. * @params bool $bool
  683. * @return void
  684. */
  685. public function testMe() {}
  686. /**
  687. * @params bool $bool
  688. * @return void
  689. */
  690. public function testMe2() {}
  691. }
  692. ',
  693. ],
  694. 'base case' => [
  695. '<?php
  696. /**
  697. * @group fast
  698. * @group slow
  699. */
  700. class FooTest extends \PHPUnit_Framework_TestCase {}
  701. ',
  702. '<?php
  703. /**
  704. * @group slow
  705. * @group fast
  706. */
  707. class FooTest extends \PHPUnit_Framework_TestCase {}
  708. ',
  709. ],
  710. 'preserve positions if other docblock parts are present' => [
  711. '<?php
  712. /**
  713. * Comment 1
  714. * @group fast
  715. * Comment 3
  716. * @group slow
  717. * Comment 2
  718. */
  719. class FooTest extends \PHPUnit_Framework_TestCase {}
  720. ',
  721. '<?php
  722. /**
  723. * Comment 1
  724. * @group slow
  725. * Comment 2
  726. * @group fast
  727. * Comment 3
  728. */
  729. class FooTest extends \PHPUnit_Framework_TestCase {}
  730. ',
  731. ],
  732. 'case-insensitive' => [
  733. '<?php
  734. /**
  735. * @group A
  736. * @group c
  737. * @group D
  738. * @group E
  739. */
  740. class FooTest extends \PHPUnit_Framework_TestCase {}
  741. ',
  742. '<?php
  743. /**
  744. * @group A
  745. * @group E
  746. * @group c
  747. * @group D
  748. */
  749. class FooTest extends \PHPUnit_Framework_TestCase {}
  750. ',
  751. ],
  752. 'data provider' => [
  753. '<?php
  754. class FooTest extends \PHPUnit_Framework_TestCase
  755. {
  756. /**
  757. * @group fast
  758. * @dataProvider provide
  759. * @group slow
  760. */
  761. public function testMe() {}
  762. }
  763. ',
  764. '<?php
  765. class FooTest extends \PHPUnit_Framework_TestCase
  766. {
  767. /**
  768. * @group slow
  769. * @dataProvider provide
  770. * @group fast
  771. */
  772. public function testMe() {}
  773. }
  774. ',
  775. ],
  776. ];
  777. }
  778. /**
  779. * @param string $expected
  780. * @param null|string $input
  781. *
  782. * @dataProvider provideFixWithInternalCases
  783. */
  784. public function testFixWithInternal($expected, $input = null)
  785. {
  786. $this->fixer->configure([
  787. 'annotations' => [
  788. 'internal',
  789. ],
  790. ]);
  791. $this->doTest($expected, $input);
  792. }
  793. public function provideFixWithInternalCases()
  794. {
  795. return [
  796. 'skip on 1 or 0 occurrences' => [
  797. '<?php
  798. class FooTest extends \PHPUnit_Framework_TestCase {
  799. /**
  800. * @internal Foo
  801. * @params bool $bool
  802. * @return void
  803. */
  804. public function testMe() {}
  805. /**
  806. * @params bool $bool
  807. * @return void
  808. */
  809. public function testMe2() {}
  810. }
  811. ',
  812. ],
  813. 'base case' => [
  814. '<?php
  815. /**
  816. * @internal Bar
  817. * @internal Foo
  818. */
  819. class FooTest extends \PHPUnit_Framework_TestCase {}
  820. ',
  821. '<?php
  822. /**
  823. * @internal Foo
  824. * @internal Bar
  825. */
  826. class FooTest extends \PHPUnit_Framework_TestCase {}
  827. ',
  828. ],
  829. 'preserve positions if other docblock parts are present' => [
  830. '<?php
  831. /**
  832. * Comment 1
  833. * @internal Bar
  834. * Comment 3
  835. * @internal Foo
  836. * Comment 2
  837. */
  838. class FooTest extends \PHPUnit_Framework_TestCase {}
  839. ',
  840. '<?php
  841. /**
  842. * Comment 1
  843. * @internal Foo
  844. * Comment 2
  845. * @internal Bar
  846. * Comment 3
  847. */
  848. class FooTest extends \PHPUnit_Framework_TestCase {}
  849. ',
  850. ],
  851. 'case-insensitive' => [
  852. '<?php
  853. /**
  854. * @internal A
  855. * @internal c
  856. * @internal D
  857. * @internal E
  858. */
  859. class FooTest extends \PHPUnit_Framework_TestCase {}
  860. ',
  861. '<?php
  862. /**
  863. * @internal A
  864. * @internal E
  865. * @internal c
  866. * @internal D
  867. */
  868. class FooTest extends \PHPUnit_Framework_TestCase {}
  869. ',
  870. ],
  871. 'data provider' => [
  872. '<?php
  873. class FooTest extends \PHPUnit_Framework_TestCase
  874. {
  875. /**
  876. * @internal Bar
  877. * @dataProvider provide
  878. * @internal Foo
  879. */
  880. public function testMe() {}
  881. }
  882. ',
  883. '<?php
  884. class FooTest extends \PHPUnit_Framework_TestCase
  885. {
  886. /**
  887. * @internal Foo
  888. * @dataProvider provide
  889. * @internal Bar
  890. */
  891. public function testMe() {}
  892. }
  893. ',
  894. ],
  895. ];
  896. }
  897. /**
  898. * @param string $expected
  899. * @param null|string $input
  900. *
  901. * @dataProvider provideFixWithRequiresCases
  902. */
  903. public function testFixWithRequires($expected, $input = null)
  904. {
  905. $this->fixer->configure([
  906. 'annotations' => [
  907. 'requires',
  908. ],
  909. ]);
  910. $this->doTest($expected, $input);
  911. }
  912. public function provideFixWithRequiresCases()
  913. {
  914. return [
  915. 'skip on 1 or 0 occurrences' => [
  916. '<?php
  917. class FooTest extends \PHPUnit_Framework_TestCase {
  918. /**
  919. * @requires function json_decode
  920. * @params bool $bool
  921. * @return void
  922. */
  923. public function testMe() {}
  924. /**
  925. * @params bool $bool
  926. * @return void
  927. */
  928. public function testMe2() {}
  929. }
  930. ',
  931. ],
  932. 'base case' => [
  933. '<?php
  934. /**
  935. * @requires extension redis
  936. * @requires function json_decode
  937. */
  938. class FooTest extends \PHPUnit_Framework_TestCase {}
  939. ',
  940. '<?php
  941. /**
  942. * @requires function json_decode
  943. * @requires extension redis
  944. */
  945. class FooTest extends \PHPUnit_Framework_TestCase {}
  946. ',
  947. ],
  948. 'preserve positions if other docblock parts are present' => [
  949. '<?php
  950. /**
  951. * Comment 1
  952. * @requires extension redis
  953. * Comment 3
  954. * @requires function json_decode
  955. * Comment 2
  956. */
  957. class FooTest extends \PHPUnit_Framework_TestCase {}
  958. ',
  959. '<?php
  960. /**
  961. * Comment 1
  962. * @requires function json_decode
  963. * Comment 2
  964. * @requires extension redis
  965. * Comment 3
  966. */
  967. class FooTest extends \PHPUnit_Framework_TestCase {}
  968. ',
  969. ],
  970. 'case-insensitive' => [
  971. '<?php
  972. /**
  973. * @requires extension redis
  974. * @requires function json_decode
  975. * @requires OS Linux
  976. * @requires PHP 7.2
  977. */
  978. class FooTest extends \PHPUnit_Framework_TestCase {}
  979. ',
  980. '<?php
  981. /**
  982. * @requires PHP 7.2
  983. * @requires function json_decode
  984. * @requires extension redis
  985. * @requires OS Linux
  986. */
  987. class FooTest extends \PHPUnit_Framework_TestCase {}
  988. ',
  989. ],
  990. 'data provider' => [
  991. '<?php
  992. class FooTest extends \PHPUnit_Framework_TestCase
  993. {
  994. /**
  995. * @requires extension redis
  996. * @dataProvider provide
  997. * @requires function json_decode
  998. */
  999. public function testMe() {}
  1000. }
  1001. ',
  1002. '<?php
  1003. class FooTest extends \PHPUnit_Framework_TestCase
  1004. {
  1005. /**
  1006. * @requires function json_decode
  1007. * @dataProvider provide
  1008. * @requires extension redis
  1009. */
  1010. public function testMe() {}
  1011. }
  1012. ',
  1013. ],
  1014. ];
  1015. }
  1016. /**
  1017. * @param string $expected
  1018. * @param null|string $input
  1019. *
  1020. * @dataProvider provideFixWithThrowsCases
  1021. */
  1022. public function testFixWithThrows($expected, $input = null)
  1023. {
  1024. $this->fixer->configure([
  1025. 'annotations' => [
  1026. 'throws',
  1027. ],
  1028. ]);
  1029. $this->doTest($expected, $input);
  1030. }
  1031. public function provideFixWithThrowsCases()
  1032. {
  1033. return [
  1034. 'skip on 1 or 0 occurrences' => [
  1035. '<?php
  1036. class Foo {
  1037. /**
  1038. * @throws Bar
  1039. * @params bool $bool
  1040. * @return void
  1041. */
  1042. public function bar() {}
  1043. /**
  1044. * @params bool $bool
  1045. * @return void
  1046. */
  1047. public function baz() {}
  1048. }
  1049. ',
  1050. ],
  1051. 'base case' => [
  1052. '<?php
  1053. class Foo
  1054. {
  1055. /**
  1056. * @throws Bar
  1057. * @throws Baz
  1058. */
  1059. public function bar() {}
  1060. }
  1061. ',
  1062. '<?php
  1063. class Foo
  1064. {
  1065. /**
  1066. * @throws Baz
  1067. * @throws Bar
  1068. */
  1069. public function bar() {}
  1070. }
  1071. ',
  1072. ],
  1073. 'preserve positions if other docblock parts are present' => [
  1074. '<?php
  1075. class Foo
  1076. {
  1077. /**
  1078. * Comment 1
  1079. * @throws Bar
  1080. * Comment 3
  1081. * @throws Baz
  1082. * Comment 2
  1083. */
  1084. public function bar() {}
  1085. }
  1086. ',
  1087. '<?php
  1088. class Foo
  1089. {
  1090. /**
  1091. * Comment 1
  1092. * @throws Baz
  1093. * Comment 2
  1094. * @throws Bar
  1095. * Comment 3
  1096. */
  1097. public function bar() {}
  1098. }
  1099. ',
  1100. ],
  1101. 'case-insensitive' => [
  1102. '<?php
  1103. class Foo
  1104. {
  1105. /**
  1106. * @throws A
  1107. * @throws b
  1108. * @throws C
  1109. */
  1110. public function bar() {}
  1111. }
  1112. ',
  1113. '<?php
  1114. class Foo
  1115. {
  1116. /**
  1117. * @throws b
  1118. * @throws C
  1119. * @throws A
  1120. */
  1121. public function bar() {}
  1122. }
  1123. ',
  1124. ],
  1125. 'fully-qualified' => [
  1126. '<?php
  1127. class Foo
  1128. {
  1129. /**
  1130. * @throws \Bar\Baz\Qux
  1131. * @throws Bar
  1132. * @throws Foo
  1133. */
  1134. public function bar() {}
  1135. }
  1136. ',
  1137. '<?php
  1138. class Foo
  1139. {
  1140. /**
  1141. * @throws Bar
  1142. * @throws \Bar\Baz\Qux
  1143. * @throws Foo
  1144. */
  1145. public function bar() {}
  1146. }
  1147. ',
  1148. ],
  1149. ];
  1150. }
  1151. /**
  1152. * @param string $expected
  1153. * @param null|string $input
  1154. *
  1155. * @dataProvider provideFixWithUsesCases
  1156. */
  1157. public function testFixWithUses($expected, $input = null)
  1158. {
  1159. $this->fixer->configure([
  1160. 'annotations' => [
  1161. 'uses',
  1162. ],
  1163. ]);
  1164. $this->doTest($expected, $input);
  1165. }
  1166. public function provideFixWithUsesCases()
  1167. {
  1168. return [
  1169. 'skip on 1 or 0 occurrences' => [
  1170. '<?php
  1171. class FooTest extends \PHPUnit_Framework_TestCase {
  1172. /**
  1173. * @uses Foo
  1174. * @params bool $bool
  1175. * @return void
  1176. */
  1177. public function testMe() {}
  1178. /**
  1179. * @params bool $bool
  1180. * @return void
  1181. */
  1182. public function testMe2() {}
  1183. }
  1184. ',
  1185. ],
  1186. 'base case' => [
  1187. '<?php
  1188. /**
  1189. * @uses Bar
  1190. * @uses Foo
  1191. */
  1192. class FooTest extends \PHPUnit_Framework_TestCase {}
  1193. ',
  1194. '<?php
  1195. /**
  1196. * @uses Foo
  1197. * @uses Bar
  1198. */
  1199. class FooTest extends \PHPUnit_Framework_TestCase {}
  1200. ',
  1201. ],
  1202. 'preserve positions if other docblock parts are present' => [
  1203. '<?php
  1204. /**
  1205. * Comment 1
  1206. * @uses Bar
  1207. * Comment 3
  1208. * @uses Foo
  1209. * Comment 2
  1210. */
  1211. class FooTest extends \PHPUnit_Framework_TestCase {}
  1212. ',
  1213. '<?php
  1214. /**
  1215. * Comment 1
  1216. * @uses Foo
  1217. * Comment 2
  1218. * @uses Bar
  1219. * Comment 3
  1220. */
  1221. class FooTest extends \PHPUnit_Framework_TestCase {}
  1222. ',
  1223. ],
  1224. 'case-insensitive' => [
  1225. '<?php
  1226. /**
  1227. * @uses A
  1228. * @uses c
  1229. * @uses D
  1230. * @uses E
  1231. */
  1232. class FooTest extends \PHPUnit_Framework_TestCase {}
  1233. ',
  1234. '<?php
  1235. /**
  1236. * @uses A
  1237. * @uses E
  1238. * @uses c
  1239. * @uses D
  1240. */
  1241. class FooTest extends \PHPUnit_Framework_TestCase {}
  1242. ',
  1243. ],
  1244. 'data provider' => [
  1245. '<?php
  1246. class FooTest extends \PHPUnit_Framework_TestCase
  1247. {
  1248. /**
  1249. * @uses Bar
  1250. * @dataProvider provide
  1251. * @uses Foo
  1252. */
  1253. public function testMe() {}
  1254. }
  1255. ',
  1256. '<?php
  1257. class FooTest extends \PHPUnit_Framework_TestCase
  1258. {
  1259. /**
  1260. * @uses Foo
  1261. * @dataProvider provide
  1262. * @uses Bar
  1263. */
  1264. public function testMe() {}
  1265. }
  1266. ',
  1267. ],
  1268. ];
  1269. }
  1270. /**
  1271. * @param string $expected
  1272. * @param null|string $input
  1273. *
  1274. * @dataProvider provideFixWithMultipleConfiguredAnnotationsCases
  1275. */
  1276. public function testFixWithMultipleConfiguredAnnotations($expected, $input = null)
  1277. {
  1278. $this->fixer->configure([
  1279. 'annotations' => [
  1280. 'covers',
  1281. 'uses',
  1282. ],
  1283. ]);
  1284. $this->doTest($expected, $input);
  1285. }
  1286. public function provideFixWithMultipleConfiguredAnnotationsCases()
  1287. {
  1288. return [
  1289. 'skip on 1 or 0 occurrences' => [
  1290. '<?php
  1291. class FooTest extends \PHPUnit_Framework_TestCase {
  1292. /**
  1293. * @uses Foo
  1294. * @covers Baz
  1295. * @params bool $bool
  1296. * @return void
  1297. */
  1298. public function testMe() {}
  1299. /**
  1300. * @params bool $bool
  1301. * @return void
  1302. */
  1303. public function testMe2() {}
  1304. }
  1305. ',
  1306. ],
  1307. 'base case' => [
  1308. '<?php
  1309. /**
  1310. * @uses Bar
  1311. * @uses Foo
  1312. * @covers Baz
  1313. * @covers Qux
  1314. */
  1315. class FooTest extends \PHPUnit_Framework_TestCase {}
  1316. ',
  1317. '<?php
  1318. /**
  1319. * @uses Foo
  1320. * @uses Bar
  1321. * @covers Qux
  1322. * @covers Baz
  1323. */
  1324. class FooTest extends \PHPUnit_Framework_TestCase {}
  1325. ',
  1326. ],
  1327. 'preserve positions if other docblock parts are present' => [
  1328. '<?php
  1329. /**
  1330. * Comment 1
  1331. * @uses Bar
  1332. * Comment 3
  1333. * @uses Foo
  1334. * Comment 2
  1335. * @covers Baz
  1336. * Comment 5
  1337. * @covers Qux
  1338. * Comment 4
  1339. */
  1340. class FooTest extends \PHPUnit_Framework_TestCase {}
  1341. ',
  1342. '<?php
  1343. /**
  1344. * Comment 1
  1345. * @uses Foo
  1346. * Comment 2
  1347. * @uses Bar
  1348. * Comment 3
  1349. * @covers Qux
  1350. * Comment 4
  1351. * @covers Baz
  1352. * Comment 5
  1353. */
  1354. class FooTest extends \PHPUnit_Framework_TestCase {}
  1355. ',
  1356. ],
  1357. 'case-insensitive' => [
  1358. '<?php
  1359. /**
  1360. * @uses A
  1361. * @uses c
  1362. * @covers D
  1363. * @covers e
  1364. */
  1365. class FooTest extends \PHPUnit_Framework_TestCase {}
  1366. ',
  1367. '<?php
  1368. /**
  1369. * @uses c
  1370. * @uses A
  1371. * @covers e
  1372. * @covers D
  1373. */
  1374. class FooTest extends \PHPUnit_Framework_TestCase {}
  1375. ',
  1376. ],
  1377. 'data provider' => [
  1378. '<?php
  1379. class FooTest extends \PHPUnit_Framework_TestCase
  1380. {
  1381. /**
  1382. * @uses Bar
  1383. * @dataProvider provideOne
  1384. * @uses Foo
  1385. * @dataProvider provideTwo
  1386. * @covers Baz
  1387. * @dataProvider provideThree
  1388. * @covers Qux
  1389. */
  1390. public function testMe() {}
  1391. }
  1392. ',
  1393. '<?php
  1394. class FooTest extends \PHPUnit_Framework_TestCase
  1395. {
  1396. /**
  1397. * @uses Foo
  1398. * @dataProvider provideOne
  1399. * @uses Bar
  1400. * @dataProvider provideTwo
  1401. * @covers Qux
  1402. * @dataProvider provideThree
  1403. * @covers Baz
  1404. */
  1405. public function testMe() {}
  1406. }
  1407. ',
  1408. ],
  1409. ];
  1410. }
  1411. }