PhpdocOrderByValueFixerTest.php 61 KB

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