PhpdocOrderByValueFixerTest.php 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033
  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\ConfigurationException\InvalidFixerConfigurationException;
  14. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  15. /**
  16. * @author Filippo Tessarotto <zoeslam@gmail.com>
  17. * @author Andreas Möller <am@localheinz.com>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocOrderByValueFixer
  22. */
  23. final class PhpdocOrderByValueFixerTest extends AbstractFixerTestCase
  24. {
  25. /**
  26. * @dataProvider provideConfigureRejectsInvalidControlStatementCases
  27. *
  28. * @param mixed $annotation
  29. */
  30. public function testConfigureRejectsInvalidControlStatement($annotation): void
  31. {
  32. $this->expectException(InvalidFixerConfigurationException::class);
  33. $this->fixer->configure([
  34. 'annotations' => [
  35. $annotation,
  36. ],
  37. ]);
  38. }
  39. public static function provideConfigureRejectsInvalidControlStatementCases(): iterable
  40. {
  41. yield 'null' => [null];
  42. yield 'false' => [false];
  43. yield 'true' => [true];
  44. yield 'int' => [0];
  45. yield 'float' => [3.14];
  46. yield 'array' => [[]];
  47. yield 'object' => [new \stdClass()];
  48. yield 'unknown' => ['foo'];
  49. }
  50. /**
  51. * @dataProvider provideFixWithCoversCases
  52. */
  53. public function testFixWithDefaultConfiguration(string $expected, ?string $input = null): void
  54. {
  55. $this->doTest($expected, $input);
  56. }
  57. /**
  58. * @dataProvider provideFixWithAuthorCases
  59. */
  60. public function testFixWithAuthor(string $expected, ?string $input = null): void
  61. {
  62. $this->fixer->configure([
  63. 'annotations' => [
  64. 'author',
  65. ],
  66. ]);
  67. $this->doTest($expected, $input);
  68. }
  69. public static function provideFixWithAuthorCases(): iterable
  70. {
  71. yield 'skip on 1 or 0 occurrences' => [
  72. '<?php
  73. class FooTest extends \PHPUnit_Framework_TestCase {
  74. /**
  75. * @author Bob
  76. * @params bool $bool
  77. * @return void
  78. */
  79. public function testMe() {}
  80. /**
  81. * @params bool $bool
  82. * @return void
  83. */
  84. public function testMe2() {}
  85. }
  86. ',
  87. ];
  88. yield 'base case' => [
  89. '<?php
  90. /**
  91. * @author Alice
  92. * @author Bob
  93. */
  94. class FooTest extends \PHPUnit_Framework_TestCase {}
  95. ',
  96. '<?php
  97. /**
  98. * @author Bob
  99. * @author Alice
  100. */
  101. class FooTest extends \PHPUnit_Framework_TestCase {}
  102. ',
  103. ];
  104. yield 'preserve positions if other docblock parts are present' => [
  105. '<?php
  106. /**
  107. * Comment 1
  108. * @author Alice
  109. * Comment 3
  110. * @author Bob
  111. * Comment 2
  112. */
  113. class FooTest extends \PHPUnit_Framework_TestCase {}
  114. ',
  115. '<?php
  116. /**
  117. * Comment 1
  118. * @author Bob
  119. * Comment 2
  120. * @author Alice
  121. * Comment 3
  122. */
  123. class FooTest extends \PHPUnit_Framework_TestCase {}
  124. ',
  125. ];
  126. yield 'case-insensitive' => [
  127. '<?php
  128. /**
  129. * @author Alice
  130. * @author chris
  131. * @author Daniel
  132. * @author Erna
  133. */
  134. class FooTest extends \PHPUnit_Framework_TestCase {}
  135. ',
  136. '<?php
  137. /**
  138. * @author Alice
  139. * @author Erna
  140. * @author chris
  141. * @author Daniel
  142. */
  143. class FooTest extends \PHPUnit_Framework_TestCase {}
  144. ',
  145. ];
  146. yield 'data provider' => [
  147. '<?php
  148. class FooTest extends \PHPUnit_Framework_TestCase
  149. {
  150. /**
  151. * @author Alice
  152. * @dataProvider provide
  153. * @author Bob
  154. */
  155. public function testMe() {}
  156. }
  157. ',
  158. '<?php
  159. class FooTest extends \PHPUnit_Framework_TestCase
  160. {
  161. /**
  162. * @author Bob
  163. * @dataProvider provide
  164. * @author Alice
  165. */
  166. public function testMe() {}
  167. }
  168. ',
  169. ];
  170. }
  171. /**
  172. * @dataProvider provideFixWithCoversCases
  173. */
  174. public function testFixWithCovers(string $expected, ?string $input = null): void
  175. {
  176. $this->fixer->configure([
  177. 'annotations' => [
  178. 'covers',
  179. ],
  180. ]);
  181. $this->doTest($expected, $input);
  182. }
  183. public static function provideFixWithCoversCases(): iterable
  184. {
  185. yield 'skip on 1 or 0 occurrences' => [
  186. '<?php
  187. class FooTest extends \PHPUnit_Framework_TestCase {
  188. /**
  189. * @covers Foo
  190. * @params bool $bool
  191. * @return void
  192. */
  193. public function testMe() {}
  194. /**
  195. * @params bool $bool
  196. * @return void
  197. */
  198. public function testMe2() {}
  199. }
  200. ',
  201. ];
  202. yield 'base case' => [
  203. '<?php
  204. /**
  205. * @covers Bar
  206. * @covers Foo
  207. */
  208. class FooTest extends \PHPUnit_Framework_TestCase {}
  209. ',
  210. '<?php
  211. /**
  212. * @covers Foo
  213. * @covers Bar
  214. */
  215. class FooTest extends \PHPUnit_Framework_TestCase {}
  216. ',
  217. ];
  218. yield 'preserve positions if other docblock parts are present' => [
  219. '<?php
  220. /**
  221. * Comment 1
  222. * @covers Bar
  223. * Comment 3
  224. * @covers Foo
  225. * Comment 2
  226. */
  227. class FooTest extends \PHPUnit_Framework_TestCase {}
  228. ',
  229. '<?php
  230. /**
  231. * Comment 1
  232. * @covers Foo
  233. * Comment 2
  234. * @covers Bar
  235. * Comment 3
  236. */
  237. class FooTest extends \PHPUnit_Framework_TestCase {}
  238. ',
  239. ];
  240. yield 'case-insensitive' => [
  241. '<?php
  242. /**
  243. * @covers A
  244. * @covers c
  245. * @covers D
  246. * @covers E
  247. */
  248. class FooTest extends \PHPUnit_Framework_TestCase {}
  249. ',
  250. '<?php
  251. /**
  252. * @covers A
  253. * @covers E
  254. * @covers c
  255. * @covers D
  256. */
  257. class FooTest extends \PHPUnit_Framework_TestCase {}
  258. ',
  259. ];
  260. yield 'data provider' => [
  261. '<?php
  262. class FooTest extends \PHPUnit_Framework_TestCase
  263. {
  264. /**
  265. * @covers Bar
  266. * @dataProvider provide
  267. * @covers Foo
  268. */
  269. public function testMe() {}
  270. }
  271. ',
  272. '<?php
  273. class FooTest extends \PHPUnit_Framework_TestCase
  274. {
  275. /**
  276. * @covers Foo
  277. * @dataProvider provide
  278. * @covers Bar
  279. */
  280. public function testMe() {}
  281. }
  282. ',
  283. ];
  284. }
  285. /**
  286. * @dataProvider provideFixWithCoversNothingCases
  287. */
  288. public function testFixWithCoversNothing(string $expected, ?string $input = null): void
  289. {
  290. $this->fixer->configure([
  291. 'annotations' => [
  292. 'coversNothing',
  293. ],
  294. ]);
  295. $this->doTest($expected, $input);
  296. }
  297. public static function provideFixWithCoversNothingCases(): iterable
  298. {
  299. yield 'skip on 1 or 0 occurrences' => [
  300. '<?php
  301. class FooTest extends \PHPUnit_Framework_TestCase {
  302. /**
  303. * @coversNothing Foo
  304. * @params bool $bool
  305. * @return void
  306. */
  307. public function testMe() {}
  308. /**
  309. * @params bool $bool
  310. * @return void
  311. */
  312. public function testMe2() {}
  313. }
  314. ',
  315. ];
  316. yield 'base case' => [
  317. '<?php
  318. /**
  319. * @coversNothing Bar
  320. * @coversNothing Foo
  321. */
  322. class FooTest extends \PHPUnit_Framework_TestCase {}
  323. ',
  324. '<?php
  325. /**
  326. * @coversNothing Foo
  327. * @coversNothing Bar
  328. */
  329. class FooTest extends \PHPUnit_Framework_TestCase {}
  330. ',
  331. ];
  332. yield 'preserve positions if other docblock parts are present' => [
  333. '<?php
  334. /**
  335. * Comment 1
  336. * @coversNothing Bar
  337. * Comment 3
  338. * @coversNothing Foo
  339. * Comment 2
  340. */
  341. class FooTest extends \PHPUnit_Framework_TestCase {}
  342. ',
  343. '<?php
  344. /**
  345. * Comment 1
  346. * @coversNothing Foo
  347. * Comment 2
  348. * @coversNothing Bar
  349. * Comment 3
  350. */
  351. class FooTest extends \PHPUnit_Framework_TestCase {}
  352. ',
  353. ];
  354. yield 'case-insensitive' => [
  355. '<?php
  356. /**
  357. * @coversNothing A
  358. * @coversNothing c
  359. * @coversNothing D
  360. * @coversNothing E
  361. */
  362. class FooTest extends \PHPUnit_Framework_TestCase {}
  363. ',
  364. '<?php
  365. /**
  366. * @coversNothing A
  367. * @coversNothing E
  368. * @coversNothing c
  369. * @coversNothing D
  370. */
  371. class FooTest extends \PHPUnit_Framework_TestCase {}
  372. ',
  373. ];
  374. yield 'data provider' => [
  375. '<?php
  376. class FooTest extends \PHPUnit_Framework_TestCase
  377. {
  378. /**
  379. * @coversNothing Bar
  380. * @dataProvider provide
  381. * @coversNothing Foo
  382. */
  383. public function testMe() {}
  384. }
  385. ',
  386. '<?php
  387. class FooTest extends \PHPUnit_Framework_TestCase
  388. {
  389. /**
  390. * @coversNothing Foo
  391. * @dataProvider provide
  392. * @coversNothing Bar
  393. */
  394. public function testMe() {}
  395. }
  396. ',
  397. ];
  398. }
  399. /**
  400. * @dataProvider provideFixWithDataProviderCases
  401. */
  402. public function testFixWithDataProvider(string $expected, ?string $input = null): void
  403. {
  404. $this->fixer->configure([
  405. 'annotations' => [
  406. 'dataProvider',
  407. ],
  408. ]);
  409. $this->doTest($expected, $input);
  410. }
  411. public static function provideFixWithDataProviderCases(): iterable
  412. {
  413. yield 'skip on 1 or 0 occurrences' => [
  414. '<?php
  415. class FooTest extends \PHPUnit_Framework_TestCase {
  416. /**
  417. * @dataProvider Foo::provideData()
  418. * @params bool $bool
  419. * @return void
  420. */
  421. public function testMe() {}
  422. /**
  423. * @params bool $bool
  424. * @return void
  425. */
  426. public function testMe2() {}
  427. }
  428. ',
  429. ];
  430. yield 'base case' => [
  431. '<?php
  432. /**
  433. * @dataProvider Bar::provideData()
  434. * @dataProvider Foo::provideData()
  435. */
  436. class FooTest extends \PHPUnit_Framework_TestCase {}
  437. ',
  438. '<?php
  439. /**
  440. * @dataProvider Foo::provideData()
  441. * @dataProvider Bar::provideData()
  442. */
  443. class FooTest extends \PHPUnit_Framework_TestCase {}
  444. ',
  445. ];
  446. yield 'preserve positions if other docblock parts are present' => [
  447. '<?php
  448. /**
  449. * Comment 1
  450. * @dataProvider Bar::provideData()
  451. * Comment 3
  452. * @dataProvider Foo::provideData()
  453. * Comment 2
  454. */
  455. class FooTest extends \PHPUnit_Framework_TestCase {}
  456. ',
  457. '<?php
  458. /**
  459. * Comment 1
  460. * @dataProvider Foo::provideData()
  461. * Comment 2
  462. * @dataProvider Bar::provideData()
  463. * Comment 3
  464. */
  465. class FooTest extends \PHPUnit_Framework_TestCase {}
  466. ',
  467. ];
  468. yield 'case-insensitive' => [
  469. '<?php
  470. /**
  471. * @dataProvider A::provideData()
  472. * @dataProvider c::provideData()
  473. * @dataProvider D::provideData()
  474. * @dataProvider E::provideData()
  475. */
  476. class FooTest extends \PHPUnit_Framework_TestCase {}
  477. ',
  478. '<?php
  479. /**
  480. * @dataProvider A::provideData()
  481. * @dataProvider E::provideData()
  482. * @dataProvider c::provideData()
  483. * @dataProvider D::provideData()
  484. */
  485. class FooTest extends \PHPUnit_Framework_TestCase {}
  486. ',
  487. ];
  488. yield 'data provider' => [
  489. '<?php
  490. class FooTest extends \PHPUnit_Framework_TestCase
  491. {
  492. /**
  493. * @dataProvider Bar::provideData()
  494. * @dataProvider dataProvider
  495. * @dataProvider Foo::provideData()
  496. */
  497. public function testMe() {}
  498. }
  499. ',
  500. '<?php
  501. class FooTest extends \PHPUnit_Framework_TestCase
  502. {
  503. /**
  504. * @dataProvider Foo::provideData()
  505. * @dataProvider dataProvider
  506. * @dataProvider Bar::provideData()
  507. */
  508. public function testMe() {}
  509. }
  510. ',
  511. ];
  512. }
  513. /**
  514. * @dataProvider provideFixWithDependsCases
  515. */
  516. public function testFixWithDepends(string $expected, ?string $input = null): void
  517. {
  518. $this->fixer->configure([
  519. 'annotations' => [
  520. 'depends',
  521. ],
  522. ]);
  523. $this->doTest($expected, $input);
  524. }
  525. public static function provideFixWithDependsCases(): iterable
  526. {
  527. yield 'skip on 1 or 0 occurrences' => [
  528. '<?php
  529. class FooTest extends \PHPUnit_Framework_TestCase {
  530. /**
  531. * @depends testFoo
  532. * @params bool $bool
  533. * @return void
  534. */
  535. public function testMe() {}
  536. /**
  537. * @params bool $bool
  538. * @return void
  539. */
  540. public function testMe2() {}
  541. }
  542. ',
  543. ];
  544. yield 'base case' => [
  545. '<?php
  546. /**
  547. * @depends testBar
  548. * @depends testFoo
  549. */
  550. class FooTest extends \PHPUnit_Framework_TestCase {}
  551. ',
  552. '<?php
  553. /**
  554. * @depends testFoo
  555. * @depends testBar
  556. */
  557. class FooTest extends \PHPUnit_Framework_TestCase {}
  558. ',
  559. ];
  560. yield 'preserve positions if other docblock parts are present' => [
  561. '<?php
  562. /**
  563. * Comment 1
  564. * @depends testBar
  565. * Comment 3
  566. * @depends testFoo
  567. * Comment 2
  568. */
  569. class FooTest extends \PHPUnit_Framework_TestCase {}
  570. ',
  571. '<?php
  572. /**
  573. * Comment 1
  574. * @depends testFoo
  575. * Comment 2
  576. * @depends testBar
  577. * Comment 3
  578. */
  579. class FooTest extends \PHPUnit_Framework_TestCase {}
  580. ',
  581. ];
  582. yield 'case-insensitive' => [
  583. '<?php
  584. /**
  585. * @depends testA
  586. * @depends testc
  587. * @depends testD
  588. * @depends testE
  589. */
  590. class FooTest extends \PHPUnit_Framework_TestCase {}
  591. ',
  592. '<?php
  593. /**
  594. * @depends testA
  595. * @depends testE
  596. * @depends testc
  597. * @depends testD
  598. */
  599. class FooTest extends \PHPUnit_Framework_TestCase {}
  600. ',
  601. ];
  602. yield 'data provider' => [
  603. '<?php
  604. class FooTest extends \PHPUnit_Framework_TestCase
  605. {
  606. /**
  607. * @depends testBar
  608. * @dataProvider provide
  609. * @depends testFoo
  610. */
  611. public function testMe() {}
  612. }
  613. ',
  614. '<?php
  615. class FooTest extends \PHPUnit_Framework_TestCase
  616. {
  617. /**
  618. * @depends testFoo
  619. * @dataProvider provide
  620. * @depends testBar
  621. */
  622. public function testMe() {}
  623. }
  624. ',
  625. ];
  626. }
  627. /**
  628. * @dataProvider provideFixWithGroupCases
  629. */
  630. public function testFixWithGroup(string $expected, ?string $input = null): void
  631. {
  632. $this->fixer->configure([
  633. 'annotations' => [
  634. 'group',
  635. ],
  636. ]);
  637. $this->doTest($expected, $input);
  638. }
  639. public static function provideFixWithGroupCases(): iterable
  640. {
  641. yield 'skip on 1 or 0 occurrences' => [
  642. '<?php
  643. class FooTest extends \PHPUnit_Framework_TestCase {
  644. /**
  645. * @group slow
  646. * @params bool $bool
  647. * @return void
  648. */
  649. public function testMe() {}
  650. /**
  651. * @params bool $bool
  652. * @return void
  653. */
  654. public function testMe2() {}
  655. }
  656. ',
  657. ];
  658. yield 'base case' => [
  659. '<?php
  660. /**
  661. * @group fast
  662. * @group slow
  663. */
  664. class FooTest extends \PHPUnit_Framework_TestCase {}
  665. ',
  666. '<?php
  667. /**
  668. * @group slow
  669. * @group fast
  670. */
  671. class FooTest extends \PHPUnit_Framework_TestCase {}
  672. ',
  673. ];
  674. yield 'preserve positions if other docblock parts are present' => [
  675. '<?php
  676. /**
  677. * Comment 1
  678. * @group fast
  679. * Comment 3
  680. * @group slow
  681. * Comment 2
  682. */
  683. class FooTest extends \PHPUnit_Framework_TestCase {}
  684. ',
  685. '<?php
  686. /**
  687. * Comment 1
  688. * @group slow
  689. * Comment 2
  690. * @group fast
  691. * Comment 3
  692. */
  693. class FooTest extends \PHPUnit_Framework_TestCase {}
  694. ',
  695. ];
  696. yield 'case-insensitive' => [
  697. '<?php
  698. /**
  699. * @group A
  700. * @group c
  701. * @group D
  702. * @group E
  703. */
  704. class FooTest extends \PHPUnit_Framework_TestCase {}
  705. ',
  706. '<?php
  707. /**
  708. * @group A
  709. * @group E
  710. * @group c
  711. * @group D
  712. */
  713. class FooTest extends \PHPUnit_Framework_TestCase {}
  714. ',
  715. ];
  716. yield 'data provider' => [
  717. '<?php
  718. class FooTest extends \PHPUnit_Framework_TestCase
  719. {
  720. /**
  721. * @group fast
  722. * @dataProvider provide
  723. * @group slow
  724. */
  725. public function testMe() {}
  726. }
  727. ',
  728. '<?php
  729. class FooTest extends \PHPUnit_Framework_TestCase
  730. {
  731. /**
  732. * @group slow
  733. * @dataProvider provide
  734. * @group fast
  735. */
  736. public function testMe() {}
  737. }
  738. ',
  739. ];
  740. }
  741. /**
  742. * @dataProvider provideFixWithInternalCases
  743. */
  744. public function testFixWithInternal(string $expected, ?string $input = null): void
  745. {
  746. $this->fixer->configure([
  747. 'annotations' => [
  748. 'internal',
  749. ],
  750. ]);
  751. $this->doTest($expected, $input);
  752. }
  753. public static function provideFixWithInternalCases(): iterable
  754. {
  755. yield 'skip on 1 or 0 occurrences' => [
  756. '<?php
  757. class FooTest extends \PHPUnit_Framework_TestCase {
  758. /**
  759. * @internal Foo
  760. * @params bool $bool
  761. * @return void
  762. */
  763. public function testMe() {}
  764. /**
  765. * @params bool $bool
  766. * @return void
  767. */
  768. public function testMe2() {}
  769. }
  770. ',
  771. ];
  772. yield 'base case' => [
  773. '<?php
  774. /**
  775. * @internal Bar
  776. * @internal Foo
  777. */
  778. class FooTest extends \PHPUnit_Framework_TestCase {}
  779. ',
  780. '<?php
  781. /**
  782. * @internal Foo
  783. * @internal Bar
  784. */
  785. class FooTest extends \PHPUnit_Framework_TestCase {}
  786. ',
  787. ];
  788. yield 'preserve positions if other docblock parts are present' => [
  789. '<?php
  790. /**
  791. * Comment 1
  792. * @internal Bar
  793. * Comment 3
  794. * @internal Foo
  795. * Comment 2
  796. */
  797. class FooTest extends \PHPUnit_Framework_TestCase {}
  798. ',
  799. '<?php
  800. /**
  801. * Comment 1
  802. * @internal Foo
  803. * Comment 2
  804. * @internal Bar
  805. * Comment 3
  806. */
  807. class FooTest extends \PHPUnit_Framework_TestCase {}
  808. ',
  809. ];
  810. yield 'case-insensitive' => [
  811. '<?php
  812. /**
  813. * @internal A
  814. * @internal c
  815. * @internal D
  816. * @internal E
  817. */
  818. class FooTest extends \PHPUnit_Framework_TestCase {}
  819. ',
  820. '<?php
  821. /**
  822. * @internal A
  823. * @internal E
  824. * @internal c
  825. * @internal D
  826. */
  827. class FooTest extends \PHPUnit_Framework_TestCase {}
  828. ',
  829. ];
  830. yield 'data provider' => [
  831. '<?php
  832. class FooTest extends \PHPUnit_Framework_TestCase
  833. {
  834. /**
  835. * @internal Bar
  836. * @dataProvider provide
  837. * @internal Foo
  838. */
  839. public function testMe() {}
  840. }
  841. ',
  842. '<?php
  843. class FooTest extends \PHPUnit_Framework_TestCase
  844. {
  845. /**
  846. * @internal Foo
  847. * @dataProvider provide
  848. * @internal Bar
  849. */
  850. public function testMe() {}
  851. }
  852. ',
  853. ];
  854. }
  855. /**
  856. * @dataProvider provideFixWithMethodCases
  857. */
  858. public function testFixWithMethod(string $expected, ?string $input = null): void
  859. {
  860. $this->fixer->configure([
  861. 'annotations' => [
  862. 'method',
  863. ],
  864. ]);
  865. $this->doTest($expected, $input);
  866. }
  867. public static function provideFixWithMethodCases(): iterable
  868. {
  869. yield 'skip on 1 or 0 occurrences' => [
  870. '<?php
  871. /**
  872. * @method int foo(array $b)
  873. */
  874. class Foo {}
  875. ',
  876. ];
  877. yield 'base case' => [
  878. '<?php
  879. /**
  880. * @method bool bar(int $a, bool $b)
  881. * @method array|null baz()
  882. * @method int foo(array $b)
  883. */
  884. class Foo {}
  885. ',
  886. '<?php
  887. /**
  888. * @method int foo(array $b)
  889. * @method bool bar(int $a, bool $b)
  890. * @method array|null baz()
  891. */
  892. class Foo {}
  893. ',
  894. ];
  895. yield 'preserve positions if other docblock parts are present' => [
  896. '<?php
  897. /**
  898. * Comment 1
  899. * @method bool bar(int $a, bool $b)
  900. * Comment 3
  901. * @method int foo(array $b)
  902. * Comment 2
  903. */
  904. class Foo {}
  905. ',
  906. '<?php
  907. /**
  908. * Comment 1
  909. * @method int foo(array $b)
  910. * Comment 2
  911. * @method bool bar(int $a, bool $b)
  912. * Comment 3
  913. */
  914. class Foo {}
  915. ',
  916. ];
  917. yield 'case-insensitive' => [
  918. '<?php
  919. /**
  920. * @method int A()
  921. * @method bool b()
  922. * @method array|null c()
  923. * @method float D()
  924. */
  925. class Foo {}
  926. ',
  927. '<?php
  928. /**
  929. * @method array|null c()
  930. * @method float D()
  931. * @method bool b()
  932. * @method int A()
  933. */
  934. class Foo {}
  935. ',
  936. ];
  937. yield 'with-possibly-unexpected-comparable' => [
  938. '<?php
  939. /**
  940. * @method int foo(Z $b)
  941. * @method int fooA( $b)
  942. */
  943. class Foo {}
  944. ',
  945. '<?php
  946. /**
  947. * @method int fooA( $b)
  948. * @method int foo(Z $b)
  949. */
  950. class Foo {}
  951. ',
  952. ];
  953. yield 'with-and-without-types' => [
  954. '<?php
  955. /**
  956. * @method int A()
  957. * @method b()
  958. * @method array|null c()
  959. * @method D()
  960. */
  961. class Foo {}
  962. ',
  963. '<?php
  964. /**
  965. * @method array|null c()
  966. * @method D()
  967. * @method b()
  968. * @method int A()
  969. */
  970. class Foo {}
  971. ',
  972. ];
  973. }
  974. /**
  975. * @dataProvider provideFixWithMixinCases
  976. */
  977. public function testFixWithMixin(string $expected, ?string $input = null): void
  978. {
  979. $this->fixer->configure([
  980. 'annotations' => [
  981. 'mixin',
  982. ],
  983. ]);
  984. $this->doTest($expected, $input);
  985. }
  986. public static function provideFixWithMixinCases(): iterable
  987. {
  988. yield 'skip on 1 or 0 occurrences' => [
  989. '<?php
  990. /**
  991. * @package SomePackage
  992. * @mixin Bar
  993. * @license MIT
  994. */
  995. class Foo {
  996. }
  997. /**
  998. * @package SomePackage
  999. * @license MIT
  1000. */
  1001. class Foo2 {
  1002. }
  1003. ',
  1004. ];
  1005. yield 'base case' => [
  1006. '<?php
  1007. /**
  1008. * @mixin Bar1
  1009. * @mixin Bar2
  1010. * @mixin Bar3
  1011. */
  1012. class Foo {
  1013. }
  1014. ',
  1015. '<?php
  1016. /**
  1017. * @mixin Bar2
  1018. * @mixin Bar3
  1019. * @mixin Bar1
  1020. */
  1021. class Foo {
  1022. }
  1023. ',
  1024. ];
  1025. yield 'preserve positions if other docblock parts are present' => [
  1026. '<?php
  1027. /**
  1028. * Comment 1
  1029. * @mixin Bar1
  1030. * Comment 3
  1031. * @mixin Bar2
  1032. * Comment 2
  1033. */
  1034. class Foo {
  1035. }
  1036. ',
  1037. '<?php
  1038. /**
  1039. * Comment 1
  1040. * @mixin Bar2
  1041. * Comment 2
  1042. * @mixin Bar1
  1043. * Comment 3
  1044. */
  1045. class Foo {
  1046. }
  1047. ',
  1048. ];
  1049. yield 'case-insensitive' => [
  1050. '<?php
  1051. /**
  1052. * @mixin A
  1053. * @mixin b
  1054. * @mixin C
  1055. */
  1056. class Foo {
  1057. }
  1058. ',
  1059. '<?php
  1060. /**
  1061. * @mixin b
  1062. * @mixin A
  1063. * @mixin C
  1064. */
  1065. class Foo {
  1066. }
  1067. ',
  1068. ];
  1069. yield 'fully-qualified' => [
  1070. '<?php
  1071. /**
  1072. * @mixin \A\B\Bar2
  1073. * @mixin Bar1
  1074. * @mixin Bar3
  1075. */
  1076. class Foo {
  1077. }
  1078. ',
  1079. '<?php
  1080. /**
  1081. * @mixin Bar3
  1082. * @mixin Bar1
  1083. * @mixin \A\B\Bar2
  1084. */
  1085. class Foo {
  1086. }
  1087. ',
  1088. ];
  1089. }
  1090. /**
  1091. * @dataProvider provideFixWithPropertyCases
  1092. */
  1093. public function testFixWithProperty(string $expected, ?string $input = null): void
  1094. {
  1095. $this->fixer->configure([
  1096. 'annotations' => [
  1097. 'property',
  1098. ],
  1099. ]);
  1100. $this->doTest($expected, $input);
  1101. }
  1102. public static function provideFixWithPropertyCases(): iterable
  1103. {
  1104. yield 'skip on 1 or 0 occurrences' => [
  1105. '<?php
  1106. /**
  1107. * @property int|\stdClass $foo
  1108. */
  1109. class Foo {}
  1110. ',
  1111. ];
  1112. yield 'base case' => [
  1113. '<?php
  1114. /**
  1115. * @property bool $bar
  1116. * @property array|null $baz
  1117. * @property int|\stdClass $foo
  1118. */
  1119. class Foo {}
  1120. ',
  1121. '<?php
  1122. /**
  1123. * @property int|\stdClass $foo
  1124. * @property bool $bar
  1125. * @property array|null $baz
  1126. */
  1127. class Foo {}
  1128. ',
  1129. ];
  1130. yield 'preserve positions if other docblock parts are present' => [
  1131. '<?php
  1132. /**
  1133. * Comment 1
  1134. * @property bool $bar
  1135. * Comment 3
  1136. * @property int|\stdClass $foo
  1137. * Comment 2
  1138. */
  1139. class Foo {}
  1140. ',
  1141. '<?php
  1142. /**
  1143. * Comment 1
  1144. * @property int|\stdClass $foo
  1145. * Comment 2
  1146. * @property bool $bar
  1147. * Comment 3
  1148. */
  1149. class Foo {}
  1150. ',
  1151. ];
  1152. yield 'case-insensitive' => [
  1153. '<?php
  1154. /**
  1155. * @property int|\stdClass $A
  1156. * @property bool $b
  1157. * @property array|null $C
  1158. * @property float $D
  1159. */
  1160. class Foo {}
  1161. ',
  1162. '<?php
  1163. /**
  1164. * @property array|null $C
  1165. * @property float $D
  1166. * @property bool $b
  1167. * @property int|\stdClass $A
  1168. */
  1169. class Foo {}
  1170. ',
  1171. ];
  1172. yield 'with-and-without-types' => [
  1173. '<?php
  1174. /**
  1175. * @property int|\stdClass $A
  1176. * @property $b
  1177. * @property array|null $C
  1178. * @property $D
  1179. */
  1180. class Foo {}
  1181. ',
  1182. '<?php
  1183. /**
  1184. * @property array|null $C
  1185. * @property $D
  1186. * @property $b
  1187. * @property int|\stdClass $A
  1188. */
  1189. class Foo {}
  1190. ',
  1191. ];
  1192. }
  1193. /**
  1194. * @dataProvider provideFixWithPropertyReadCases
  1195. */
  1196. public function testFixWithPropertyRead(string $expected, ?string $input = null): void
  1197. {
  1198. $this->fixer->configure([
  1199. 'annotations' => [
  1200. 'property-read',
  1201. ],
  1202. ]);
  1203. $this->doTest($expected, $input);
  1204. }
  1205. public static function provideFixWithPropertyReadCases(): iterable
  1206. {
  1207. yield 'skip on 1 or 0 occurrences' => [
  1208. '<?php
  1209. /**
  1210. * @property-read int|\stdClass $foo
  1211. */
  1212. class Foo {}
  1213. ',
  1214. ];
  1215. yield 'base case' => [
  1216. '<?php
  1217. /**
  1218. * @property-read bool $bar
  1219. * @property-read array|null $baz
  1220. * @property-read int|\stdClass $foo
  1221. */
  1222. class Foo {}
  1223. ',
  1224. '<?php
  1225. /**
  1226. * @property-read int|\stdClass $foo
  1227. * @property-read bool $bar
  1228. * @property-read array|null $baz
  1229. */
  1230. class Foo {}
  1231. ',
  1232. ];
  1233. yield 'preserve positions if other docblock parts are present' => [
  1234. '<?php
  1235. /**
  1236. * Comment 1
  1237. * @property-read bool $bar
  1238. * Comment 3
  1239. * @property-read int|\stdClass $foo
  1240. * Comment 2
  1241. */
  1242. class Foo {}
  1243. ',
  1244. '<?php
  1245. /**
  1246. * Comment 1
  1247. * @property-read int|\stdClass $foo
  1248. * Comment 2
  1249. * @property-read bool $bar
  1250. * Comment 3
  1251. */
  1252. class Foo {}
  1253. ',
  1254. ];
  1255. yield 'case-insensitive' => [
  1256. '<?php
  1257. /**
  1258. * @property-read int|\stdClass $A
  1259. * @property-read bool $b
  1260. * @property-read array|null $C
  1261. * @property-read float $D
  1262. */
  1263. class Foo {}
  1264. ',
  1265. '<?php
  1266. /**
  1267. * @property-read array|null $C
  1268. * @property-read float $D
  1269. * @property-read bool $b
  1270. * @property-read int|\stdClass $A
  1271. */
  1272. class Foo {}
  1273. ',
  1274. ];
  1275. yield 'with-and-without-types' => [
  1276. '<?php
  1277. /**
  1278. * @property-read int|\stdClass $A
  1279. * @property-read $b
  1280. * @property-read array|null $C
  1281. * @property-read $D
  1282. */
  1283. class Foo {}
  1284. ',
  1285. '<?php
  1286. /**
  1287. * @property-read array|null $C
  1288. * @property-read $D
  1289. * @property-read $b
  1290. * @property-read int|\stdClass $A
  1291. */
  1292. class Foo {}
  1293. ',
  1294. ];
  1295. }
  1296. /**
  1297. * @dataProvider provideFixWithPropertyWriteCases
  1298. */
  1299. public function testFixWithPropertyWrite(string $expected, ?string $input = null): void
  1300. {
  1301. $this->fixer->configure([
  1302. 'annotations' => [
  1303. 'property-write',
  1304. ],
  1305. ]);
  1306. $this->doTest($expected, $input);
  1307. }
  1308. public static function provideFixWithPropertyWriteCases(): iterable
  1309. {
  1310. yield 'skip on 1 or 0 occurrences' => [
  1311. '<?php
  1312. /**
  1313. * @property-write int|\stdClass $foo
  1314. */
  1315. class Foo {}
  1316. ',
  1317. ];
  1318. yield 'base case' => [
  1319. '<?php
  1320. /**
  1321. * @property-write bool $bar
  1322. * @property-write array|null $baz
  1323. * @property-write int|\stdClass $foo
  1324. */
  1325. class Foo {}
  1326. ',
  1327. '<?php
  1328. /**
  1329. * @property-write int|\stdClass $foo
  1330. * @property-write bool $bar
  1331. * @property-write array|null $baz
  1332. */
  1333. class Foo {}
  1334. ',
  1335. ];
  1336. yield 'preserve positions if other docblock parts are present' => [
  1337. '<?php
  1338. /**
  1339. * Comment 1
  1340. * @property-write bool $bar
  1341. * Comment 3
  1342. * @property-write int|\stdClass $foo
  1343. * Comment 2
  1344. */
  1345. class Foo {}
  1346. ',
  1347. '<?php
  1348. /**
  1349. * Comment 1
  1350. * @property-write int|\stdClass $foo
  1351. * Comment 2
  1352. * @property-write bool $bar
  1353. * Comment 3
  1354. */
  1355. class Foo {}
  1356. ',
  1357. ];
  1358. yield 'case-insensitive' => [
  1359. '<?php
  1360. /**
  1361. * @property-write int|\stdClass $A
  1362. * @property-write bool $b
  1363. * @property-write array|null $C
  1364. * @property-write float $D
  1365. */
  1366. class Foo {}
  1367. ',
  1368. '<?php
  1369. /**
  1370. * @property-write array|null $C
  1371. * @property-write float $D
  1372. * @property-write bool $b
  1373. * @property-write int|\stdClass $A
  1374. */
  1375. class Foo {}
  1376. ',
  1377. ];
  1378. yield 'with-and-without-types' => [
  1379. '<?php
  1380. /**
  1381. * @property-write int|\stdClass $A
  1382. * @property-write $b
  1383. * @property-write array|null $C
  1384. * @property-write $D
  1385. */
  1386. class Foo {}
  1387. ',
  1388. '<?php
  1389. /**
  1390. * @property-write array|null $C
  1391. * @property-write $D
  1392. * @property-write $b
  1393. * @property-write int|\stdClass $A
  1394. */
  1395. class Foo {}
  1396. ',
  1397. ];
  1398. }
  1399. /**
  1400. * @dataProvider provideFixWithRequiresCases
  1401. */
  1402. public function testFixWithRequires(string $expected, ?string $input = null): void
  1403. {
  1404. $this->fixer->configure([
  1405. 'annotations' => [
  1406. 'requires',
  1407. ],
  1408. ]);
  1409. $this->doTest($expected, $input);
  1410. }
  1411. public static function provideFixWithRequiresCases(): iterable
  1412. {
  1413. yield 'skip on 1 or 0 occurrences' => [
  1414. '<?php
  1415. class FooTest extends \PHPUnit_Framework_TestCase {
  1416. /**
  1417. * @requires function json_decode
  1418. * @params bool $bool
  1419. * @return void
  1420. */
  1421. public function testMe() {}
  1422. /**
  1423. * @params bool $bool
  1424. * @return void
  1425. */
  1426. public function testMe2() {}
  1427. }
  1428. ',
  1429. ];
  1430. yield 'base case' => [
  1431. '<?php
  1432. /**
  1433. * @requires extension redis
  1434. * @requires function json_decode
  1435. */
  1436. class FooTest extends \PHPUnit_Framework_TestCase {}
  1437. ',
  1438. '<?php
  1439. /**
  1440. * @requires function json_decode
  1441. * @requires extension redis
  1442. */
  1443. class FooTest extends \PHPUnit_Framework_TestCase {}
  1444. ',
  1445. ];
  1446. yield 'preserve positions if other docblock parts are present' => [
  1447. '<?php
  1448. /**
  1449. * Comment 1
  1450. * @requires extension redis
  1451. * Comment 3
  1452. * @requires function json_decode
  1453. * Comment 2
  1454. */
  1455. class FooTest extends \PHPUnit_Framework_TestCase {}
  1456. ',
  1457. '<?php
  1458. /**
  1459. * Comment 1
  1460. * @requires function json_decode
  1461. * Comment 2
  1462. * @requires extension redis
  1463. * Comment 3
  1464. */
  1465. class FooTest extends \PHPUnit_Framework_TestCase {}
  1466. ',
  1467. ];
  1468. yield 'case-insensitive' => [
  1469. '<?php
  1470. /**
  1471. * @requires extension redis
  1472. * @requires function json_decode
  1473. * @requires OS Linux
  1474. * @requires PHP 7.2
  1475. */
  1476. class FooTest extends \PHPUnit_Framework_TestCase {}
  1477. ',
  1478. '<?php
  1479. /**
  1480. * @requires PHP 7.2
  1481. * @requires function json_decode
  1482. * @requires extension redis
  1483. * @requires OS Linux
  1484. */
  1485. class FooTest extends \PHPUnit_Framework_TestCase {}
  1486. ',
  1487. ];
  1488. yield 'data provider' => [
  1489. '<?php
  1490. class FooTest extends \PHPUnit_Framework_TestCase
  1491. {
  1492. /**
  1493. * @requires extension redis
  1494. * @dataProvider provide
  1495. * @requires function json_decode
  1496. */
  1497. public function testMe() {}
  1498. }
  1499. ',
  1500. '<?php
  1501. class FooTest extends \PHPUnit_Framework_TestCase
  1502. {
  1503. /**
  1504. * @requires function json_decode
  1505. * @dataProvider provide
  1506. * @requires extension redis
  1507. */
  1508. public function testMe() {}
  1509. }
  1510. ',
  1511. ];
  1512. }
  1513. /**
  1514. * @dataProvider provideFixWithThrowsCases
  1515. */
  1516. public function testFixWithThrows(string $expected, ?string $input = null): void
  1517. {
  1518. $this->fixer->configure([
  1519. 'annotations' => [
  1520. 'throws',
  1521. ],
  1522. ]);
  1523. $this->doTest($expected, $input);
  1524. }
  1525. public static function provideFixWithThrowsCases(): iterable
  1526. {
  1527. yield 'skip on 1 or 0 occurrences' => [
  1528. '<?php
  1529. class Foo {
  1530. /**
  1531. * @throws Bar
  1532. * @params bool $bool
  1533. * @return void
  1534. */
  1535. public function bar() {}
  1536. /**
  1537. * @params bool $bool
  1538. * @return void
  1539. */
  1540. public function baz() {}
  1541. }
  1542. ',
  1543. ];
  1544. yield 'base case' => [
  1545. '<?php
  1546. class Foo
  1547. {
  1548. /**
  1549. * @throws Bar
  1550. * @throws Baz
  1551. */
  1552. public function bar() {}
  1553. }
  1554. ',
  1555. '<?php
  1556. class Foo
  1557. {
  1558. /**
  1559. * @throws Baz
  1560. * @throws Bar
  1561. */
  1562. public function bar() {}
  1563. }
  1564. ',
  1565. ];
  1566. yield 'preserve positions if other docblock parts are present' => [
  1567. '<?php
  1568. class Foo
  1569. {
  1570. /**
  1571. * Comment 1
  1572. * @throws Bar
  1573. * Comment 3
  1574. * @throws Baz
  1575. * Comment 2
  1576. */
  1577. public function bar() {}
  1578. }
  1579. ',
  1580. '<?php
  1581. class Foo
  1582. {
  1583. /**
  1584. * Comment 1
  1585. * @throws Baz
  1586. * Comment 2
  1587. * @throws Bar
  1588. * Comment 3
  1589. */
  1590. public function bar() {}
  1591. }
  1592. ',
  1593. ];
  1594. yield 'case-insensitive' => [
  1595. '<?php
  1596. class Foo
  1597. {
  1598. /**
  1599. * @throws A
  1600. * @throws b
  1601. * @throws C
  1602. */
  1603. public function bar() {}
  1604. }
  1605. ',
  1606. '<?php
  1607. class Foo
  1608. {
  1609. /**
  1610. * @throws b
  1611. * @throws C
  1612. * @throws A
  1613. */
  1614. public function bar() {}
  1615. }
  1616. ',
  1617. ];
  1618. yield 'fully-qualified' => [
  1619. '<?php
  1620. class Foo
  1621. {
  1622. /**
  1623. * @throws \Bar\Baz\Qux
  1624. * @throws Bar
  1625. * @throws Foo
  1626. */
  1627. public function bar() {}
  1628. }
  1629. ',
  1630. '<?php
  1631. class Foo
  1632. {
  1633. /**
  1634. * @throws Bar
  1635. * @throws \Bar\Baz\Qux
  1636. * @throws Foo
  1637. */
  1638. public function bar() {}
  1639. }
  1640. ',
  1641. ];
  1642. }
  1643. /**
  1644. * @dataProvider provideFixWithUsesCases
  1645. */
  1646. public function testFixWithUses(string $expected, ?string $input = null): void
  1647. {
  1648. $this->fixer->configure([
  1649. 'annotations' => [
  1650. 'uses',
  1651. ],
  1652. ]);
  1653. $this->doTest($expected, $input);
  1654. }
  1655. public static function provideFixWithUsesCases(): iterable
  1656. {
  1657. yield 'skip on 1 or 0 occurrences' => [
  1658. '<?php
  1659. class FooTest extends \PHPUnit_Framework_TestCase {
  1660. /**
  1661. * @uses Foo
  1662. * @params bool $bool
  1663. * @return void
  1664. */
  1665. public function testMe() {}
  1666. /**
  1667. * @params bool $bool
  1668. * @return void
  1669. */
  1670. public function testMe2() {}
  1671. }
  1672. ',
  1673. ];
  1674. yield 'base case' => [
  1675. '<?php
  1676. /**
  1677. * @uses Bar
  1678. * @uses Foo
  1679. */
  1680. class FooTest extends \PHPUnit_Framework_TestCase {}
  1681. ',
  1682. '<?php
  1683. /**
  1684. * @uses Foo
  1685. * @uses Bar
  1686. */
  1687. class FooTest extends \PHPUnit_Framework_TestCase {}
  1688. ',
  1689. ];
  1690. yield 'preserve positions if other docblock parts are present' => [
  1691. '<?php
  1692. /**
  1693. * Comment 1
  1694. * @uses Bar
  1695. * Comment 3
  1696. * @uses Foo
  1697. * Comment 2
  1698. */
  1699. class FooTest extends \PHPUnit_Framework_TestCase {}
  1700. ',
  1701. '<?php
  1702. /**
  1703. * Comment 1
  1704. * @uses Foo
  1705. * Comment 2
  1706. * @uses Bar
  1707. * Comment 3
  1708. */
  1709. class FooTest extends \PHPUnit_Framework_TestCase {}
  1710. ',
  1711. ];
  1712. yield 'case-insensitive' => [
  1713. '<?php
  1714. /**
  1715. * @uses A
  1716. * @uses c
  1717. * @uses D
  1718. * @uses E
  1719. */
  1720. class FooTest extends \PHPUnit_Framework_TestCase {}
  1721. ',
  1722. '<?php
  1723. /**
  1724. * @uses A
  1725. * @uses E
  1726. * @uses c
  1727. * @uses D
  1728. */
  1729. class FooTest extends \PHPUnit_Framework_TestCase {}
  1730. ',
  1731. ];
  1732. yield 'data provider' => [
  1733. '<?php
  1734. class FooTest extends \PHPUnit_Framework_TestCase
  1735. {
  1736. /**
  1737. * @uses Bar
  1738. * @dataProvider provide
  1739. * @uses Foo
  1740. */
  1741. public function testMe() {}
  1742. }
  1743. ',
  1744. '<?php
  1745. class FooTest extends \PHPUnit_Framework_TestCase
  1746. {
  1747. /**
  1748. * @uses Foo
  1749. * @dataProvider provide
  1750. * @uses Bar
  1751. */
  1752. public function testMe() {}
  1753. }
  1754. ',
  1755. ];
  1756. }
  1757. /**
  1758. * @dataProvider provideFixWithMultipleConfiguredAnnotationsCases
  1759. */
  1760. public function testFixWithMultipleConfiguredAnnotations(string $expected, ?string $input = null): void
  1761. {
  1762. $this->fixer->configure([
  1763. 'annotations' => [
  1764. 'covers',
  1765. 'uses',
  1766. ],
  1767. ]);
  1768. $this->doTest($expected, $input);
  1769. }
  1770. public static function provideFixWithMultipleConfiguredAnnotationsCases(): iterable
  1771. {
  1772. yield 'skip on 1 or 0 occurrences' => [
  1773. '<?php
  1774. class FooTest extends \PHPUnit_Framework_TestCase {
  1775. /**
  1776. * @uses Foo
  1777. * @covers Baz
  1778. * @params bool $bool
  1779. * @return void
  1780. */
  1781. public function testMe() {}
  1782. /**
  1783. * @params bool $bool
  1784. * @return void
  1785. */
  1786. public function testMe2() {}
  1787. }
  1788. ',
  1789. ];
  1790. yield 'base case' => [
  1791. '<?php
  1792. /**
  1793. * @uses Bar
  1794. * @uses Foo
  1795. * @covers Baz
  1796. * @covers Qux
  1797. */
  1798. class FooTest extends \PHPUnit_Framework_TestCase {}
  1799. ',
  1800. '<?php
  1801. /**
  1802. * @uses Foo
  1803. * @uses Bar
  1804. * @covers Qux
  1805. * @covers Baz
  1806. */
  1807. class FooTest extends \PHPUnit_Framework_TestCase {}
  1808. ',
  1809. ];
  1810. yield 'preserve positions if other docblock parts are present' => [
  1811. '<?php
  1812. /**
  1813. * Comment 1
  1814. * @uses Bar
  1815. * Comment 3
  1816. * @uses Foo
  1817. * Comment 2
  1818. * @covers Baz
  1819. * Comment 5
  1820. * @covers Qux
  1821. * Comment 4
  1822. */
  1823. class FooTest extends \PHPUnit_Framework_TestCase {}
  1824. ',
  1825. '<?php
  1826. /**
  1827. * Comment 1
  1828. * @uses Foo
  1829. * Comment 2
  1830. * @uses Bar
  1831. * Comment 3
  1832. * @covers Qux
  1833. * Comment 4
  1834. * @covers Baz
  1835. * Comment 5
  1836. */
  1837. class FooTest extends \PHPUnit_Framework_TestCase {}
  1838. ',
  1839. ];
  1840. yield 'case-insensitive' => [
  1841. '<?php
  1842. /**
  1843. * @uses A
  1844. * @uses c
  1845. * @covers D
  1846. * @covers e
  1847. */
  1848. class FooTest extends \PHPUnit_Framework_TestCase {}
  1849. ',
  1850. '<?php
  1851. /**
  1852. * @uses c
  1853. * @uses A
  1854. * @covers e
  1855. * @covers D
  1856. */
  1857. class FooTest extends \PHPUnit_Framework_TestCase {}
  1858. ',
  1859. ];
  1860. yield 'data provider' => [
  1861. '<?php
  1862. class FooTest extends \PHPUnit_Framework_TestCase
  1863. {
  1864. /**
  1865. * @uses Bar
  1866. * @dataProvider provideOne
  1867. * @uses Foo
  1868. * @dataProvider provideTwo
  1869. * @covers Baz
  1870. * @dataProvider provideThree
  1871. * @covers Qux
  1872. */
  1873. public function testMe() {}
  1874. }
  1875. ',
  1876. '<?php
  1877. class FooTest extends \PHPUnit_Framework_TestCase
  1878. {
  1879. /**
  1880. * @uses Foo
  1881. * @dataProvider provideOne
  1882. * @uses Bar
  1883. * @dataProvider provideTwo
  1884. * @covers Qux
  1885. * @dataProvider provideThree
  1886. * @covers Baz
  1887. */
  1888. public function testMe() {}
  1889. }
  1890. ',
  1891. ];
  1892. }
  1893. }