PhpdocOrderByValueFixerTest.php 58 KB

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