PhpUnitTestAnnotationFixerTest.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  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\PhpUnit;
  12. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  13. use PhpCsFixer\WhitespacesFixerConfig;
  14. /**
  15. * @author Gert de Pagter
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\PhpUnit\PhpUnitTestAnnotationFixer
  20. */
  21. final class PhpUnitTestAnnotationFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFixCases
  25. *
  26. * @param string $expected
  27. * @param null|string $input
  28. * @param null|array $config
  29. */
  30. public function testFix($expected, $input = null, array $config = [])
  31. {
  32. $this->fixer->configure($config);
  33. $this->doTest($expected, $input);
  34. }
  35. /**
  36. * @return array
  37. */
  38. public function provideFixCases()
  39. {
  40. return [
  41. 'Annotation is used, and it should not be' => [
  42. '<?php
  43. class Test extends \PhpUnit\FrameWork\TestCase
  44. {
  45. /**
  46. *
  47. */
  48. public function testItDoesSomething() {}
  49. }',
  50. '<?php
  51. class Test extends \PhpUnit\FrameWork\TestCase
  52. {
  53. /**
  54. * @test
  55. */
  56. public function itDoesSomething() {}
  57. }',
  58. ['style' => 'prefix'],
  59. ],
  60. 'Annotation is not used, but should be' => [
  61. '<?php
  62. class Test extends \PhpUnit\FrameWork\TestCase
  63. {
  64. /**
  65. * @test
  66. */
  67. public function itDoesSomething() {}
  68. }',
  69. '<?php
  70. class Test extends \PhpUnit\FrameWork\TestCase
  71. {
  72. public function testItDoesSomething() {}
  73. }',
  74. ['style' => 'annotation'],
  75. ],
  76. 'Annotation is not used, but should be, class is extra indented' => [
  77. '<?php
  78. if (1) {
  79. class Test extends \PhpUnit\FrameWork\TestCase
  80. {
  81. /**
  82. * @test
  83. */
  84. public function itDoesSomething() {}
  85. }
  86. }',
  87. '<?php
  88. if (1) {
  89. class Test extends \PhpUnit\FrameWork\TestCase
  90. {
  91. public function testItDoesSomething() {}
  92. }
  93. }',
  94. ['style' => 'annotation'],
  95. ],
  96. 'Annotation is not used, but should be, and there is already a docBlcok' => [
  97. '<?php
  98. class Test extends \PhpUnit\FrameWork\TestCase
  99. {
  100. /**
  101. * @dataProvider blabla
  102. *
  103. * @test
  104. */
  105. public function itDoesSomething() {}
  106. }',
  107. '<?php
  108. class Test extends \PhpUnit\FrameWork\TestCase
  109. {
  110. /**
  111. * @dataProvider blabla
  112. */
  113. public function testItDoesSomething() {}
  114. }',
  115. ['style' => 'annotation'],
  116. ],
  117. 'Annotation is used, but should not be, and it depends on other tests' => [
  118. '<?php
  119. class Test extends \PhpUnit\FrameWork\TestCase
  120. {
  121. /**
  122. *
  123. */
  124. public function testAaa () {}
  125. public function helperFunction() {}
  126. /**
  127. * @depends testAaa
  128. *
  129. *
  130. */
  131. public function testBbb () {}
  132. }',
  133. '<?php
  134. class Test extends \PhpUnit\FrameWork\TestCase
  135. {
  136. /**
  137. * @test
  138. */
  139. public function aaa () {}
  140. public function helperFunction() {}
  141. /**
  142. * @depends aaa
  143. *
  144. * @test
  145. */
  146. public function bbb () {}
  147. }',
  148. ['style' => 'prefix'],
  149. ],
  150. 'Annotation is not used, but should be, and it depends on other tests' => [
  151. '<?php
  152. class Test extends \PhpUnit\FrameWork\TestCase
  153. {
  154. /**
  155. * @test
  156. */
  157. public function aaa () {}
  158. /**
  159. * @depends aaa
  160. *
  161. * @test
  162. */
  163. public function bbb () {}
  164. }',
  165. '<?php
  166. class Test extends \PhpUnit\FrameWork\TestCase
  167. {
  168. public function testAaa () {}
  169. /**
  170. * @depends testAaa
  171. */
  172. public function testBbb () {}
  173. }',
  174. ['style' => 'annotation'],
  175. ],
  176. 'Annotation is removed, the function is one word and we want it to use camel case' => [
  177. '<?php
  178. class Test extends \PhpUnit\FrameWork\TestCase
  179. {
  180. /**
  181. *
  182. */
  183. public function testWorks() {}
  184. }',
  185. '<?php
  186. class Test extends \PhpUnit\FrameWork\TestCase
  187. {
  188. /**
  189. * @test
  190. */
  191. public function works() {}
  192. }',
  193. ],
  194. 'Annotation is removed, the function is one word and we want it to use snake case' => [
  195. '<?php
  196. class Test extends \PhpUnit\FrameWork\TestCase
  197. {
  198. /**
  199. *
  200. */
  201. public function test_works() {}
  202. }',
  203. '<?php
  204. class Test extends \PhpUnit\FrameWork\TestCase
  205. {
  206. /**
  207. * @test
  208. */
  209. public function works() {}
  210. }',
  211. ['case' => 'snake'],
  212. ],
  213. 'Annotation is added, and it is snake case' => [
  214. '<?php
  215. class Test extends \PhpUnit\FrameWork\TestCase
  216. {
  217. /**
  218. * @test
  219. */
  220. public function it_has_snake_case() {}
  221. }',
  222. '<?php
  223. class Test extends \PhpUnit\FrameWork\TestCase
  224. {
  225. public function test_it_has_snake_case() {}
  226. }',
  227. ['style' => 'annotation'],
  228. ],
  229. 'Annotation is removed, and it is snake case' => [
  230. '<?php
  231. class Test extends \PhpUnit\FrameWork\TestCase
  232. {
  233. /**
  234. *
  235. */
  236. public function test_it_has_snake_case() {}
  237. public function helper_function() {}
  238. }',
  239. '<?php
  240. class Test extends \PhpUnit\FrameWork\TestCase
  241. {
  242. /**
  243. * @test
  244. */
  245. public function it_has_snake_case() {}
  246. public function helper_function() {}
  247. }',
  248. ['case' => 'snake'],
  249. ],
  250. 'Annotation gets added, it has an @depends, and we use snake case' => [
  251. '<?php
  252. class Test extends \PhpUnit\FrameWork\TestCase
  253. {
  254. /**
  255. * @test
  256. */
  257. public function works_fine () {}
  258. /**
  259. * @depends works_fine
  260. *
  261. * @test
  262. */
  263. public function works_fine_too() {}
  264. }',
  265. '<?php
  266. class Test extends \PhpUnit\FrameWork\TestCase
  267. {
  268. public function test_works_fine () {}
  269. /**
  270. * @depends test_works_fine
  271. */
  272. public function test_works_fine_too() {}
  273. }',
  274. ['style' => 'annotation'],
  275. ],
  276. 'Annotation gets removed, it has an @depends and we use camel case' => [
  277. '<?php
  278. class Test extends \PhpUnit\FrameWork\TestCase
  279. {
  280. /**
  281. *
  282. */
  283. public function test_works_fine () {}
  284. /**
  285. *
  286. * @depends test_works_fine
  287. */
  288. public function test_works_fine_too() {}
  289. }',
  290. '<?php
  291. class Test extends \PhpUnit\FrameWork\TestCase
  292. {
  293. /**
  294. * @test
  295. */
  296. public function works_fine () {}
  297. /**
  298. * @test
  299. * @depends works_fine
  300. */
  301. public function works_fine_too() {}
  302. }',
  303. ['case' => 'snake'],
  304. ],
  305. 'Class has both camel and snake case, annotated functions and not, and wants to add annotations' => [
  306. '<?php
  307. class Test extends \PhpUnit\FrameWork\TestCase
  308. {
  309. /**
  310. * @test
  311. */
  312. public function snake_cased () {}
  313. /**
  314. * @test
  315. */
  316. public function camelCased () {}
  317. /**
  318. * Description.
  319. *
  320. * @depends camelCased
  321. *
  322. * @test
  323. */
  324. public function depends_on_someone () {}
  325. //It even has a comment
  326. public function a_helper_function () {}
  327. /**
  328. * @depends depends_on_someone
  329. *
  330. * @test
  331. */
  332. public function moreDepends() {}
  333. /**
  334. * @depends depends_on_someone
  335. *
  336. * @test
  337. */
  338. public function alreadyAnnotated() {}
  339. }',
  340. '<?php
  341. class Test extends \PhpUnit\FrameWork\TestCase
  342. {
  343. public function test_snake_cased () {}
  344. public function testCamelCased () {}
  345. /**
  346. * Description.
  347. *
  348. * @depends testCamelCased
  349. */
  350. public function test_depends_on_someone () {}
  351. //It even has a comment
  352. public function a_helper_function () {}
  353. /**
  354. * @depends test_depends_on_someone
  355. */
  356. public function testMoreDepends() {}
  357. /**
  358. * @depends test_depends_on_someone
  359. *
  360. * @test
  361. */
  362. public function alreadyAnnotated() {}
  363. }',
  364. ['style' => 'annotation'],
  365. ],
  366. 'Annotation has to be added to multiple functions' => [
  367. '<?php
  368. class Test extends \PhpUnit\FrameWork\TestCase
  369. {
  370. /**
  371. * @test
  372. */
  373. public function itWorks() {}
  374. /**
  375. * @test
  376. */
  377. public function itDoesSomething() {}
  378. }',
  379. '<?php
  380. class Test extends \PhpUnit\FrameWork\TestCase
  381. {
  382. public function testItWorks() {}
  383. public function testItDoesSomething() {}
  384. }',
  385. ['style' => 'annotation'],
  386. ],
  387. 'Annotation has to be removed from multiple functions and we use snake case' => [
  388. '<?php
  389. class Test extends \PhpUnit\FrameWork\TestCase
  390. {
  391. /**
  392. *
  393. */
  394. public function test_it_works() {}
  395. /**
  396. *
  397. */
  398. public function test_it_does_something() {}
  399. public function dataProvider() {}
  400. /**
  401. * @dataprovider dataProvider
  402. * @depends test_it_does_something
  403. */
  404. public function test_it_depend_and_has_provider() {}
  405. }',
  406. '<?php
  407. class Test extends \PhpUnit\FrameWork\TestCase
  408. {
  409. /**
  410. * @test
  411. */
  412. public function it_works() {}
  413. /**
  414. * @test
  415. */
  416. public function it_does_something() {}
  417. public function dataProvider() {}
  418. /**
  419. * @dataprovider dataProvider
  420. * @depends it_does_something
  421. */
  422. public function test_it_depend_and_has_provider() {}
  423. }',
  424. ['case' => 'snake'],
  425. ],
  426. 'Class with big doc blocks and multiple functions has to remove annotations' => [
  427. '<?php
  428. class Test extends \PhpUnit\FrameWork\TestCase
  429. {
  430. /**
  431. * This test is part of the database group and has a provider.
  432. *
  433. * @param int $paramOne
  434. * @param bool $paramTwo
  435. *
  436. *
  437. * @dataProvider provides
  438. * @group Database
  439. */
  440. public function testDatabase ($paramOne, $paramTwo) {}
  441. /**
  442. * Provider for the database test function
  443. *
  444. * @return array
  445. */
  446. public function provides() {}
  447. /**
  448. * Im just a helper function but i have test in my name.
  449. * I also have a doc Block
  450. *
  451. * @return Foo\Bar
  452. */
  453. public function help_test() {}
  454. protected function setUp() {}
  455. /**
  456. * I depend on the database function, but i already
  457. * had test in my name and a docblock
  458. *
  459. * @depends testDatabase
  460. */
  461. public function testDepends () {}
  462. }',
  463. '<?php
  464. class Test extends \PhpUnit\FrameWork\TestCase
  465. {
  466. /**
  467. * This test is part of the database group and has a provider.
  468. *
  469. * @param int $paramOne
  470. * @param bool $paramTwo
  471. *
  472. * @test
  473. * @dataProvider provides
  474. * @group Database
  475. */
  476. public function database ($paramOne, $paramTwo) {}
  477. /**
  478. * Provider for the database test function
  479. *
  480. * @return array
  481. */
  482. public function provides() {}
  483. /**
  484. * Im just a helper function but i have test in my name.
  485. * I also have a doc Block
  486. *
  487. * @return Foo\Bar
  488. */
  489. public function help_test() {}
  490. protected function setUp() {}
  491. /**
  492. * I depend on the database function, but i already
  493. * had test in my name and a docblock
  494. *
  495. * @depends database
  496. */
  497. public function testDepends () {}
  498. }',
  499. ],
  500. 'Class with big doc blocks and multiple functions has to remove annotations, but its snake case' => [
  501. '<?php
  502. class Test extends \PhpUnit\FrameWork\TestCase
  503. {
  504. /**
  505. * This test is part of the database group and has a provider.
  506. *
  507. * @param int $paramOne
  508. * @param bool $paramTwo
  509. *
  510. *
  511. * @dataProvider provides
  512. * @group Database
  513. */
  514. public function test_database ($paramOne, $paramTwo) {}
  515. /**
  516. * Provider for the database test function
  517. *
  518. * @return array
  519. */
  520. public function provides() {}
  521. /**
  522. * Im just a helper function but i have test in my name.
  523. * I also have a doc Block
  524. *
  525. * @return Foo\Bar
  526. */
  527. public function help_test() {}
  528. protected function setUp() {}
  529. /**
  530. * I depend on the database function, but i already
  531. * had test in my name and a docblock
  532. *
  533. * @depends test_database
  534. */
  535. public function testDepends () {}
  536. }',
  537. '<?php
  538. class Test extends \PhpUnit\FrameWork\TestCase
  539. {
  540. /**
  541. * This test is part of the database group and has a provider.
  542. *
  543. * @param int $paramOne
  544. * @param bool $paramTwo
  545. *
  546. * @test
  547. * @dataProvider provides
  548. * @group Database
  549. */
  550. public function database ($paramOne, $paramTwo) {}
  551. /**
  552. * Provider for the database test function
  553. *
  554. * @return array
  555. */
  556. public function provides() {}
  557. /**
  558. * Im just a helper function but i have test in my name.
  559. * I also have a doc Block
  560. *
  561. * @return Foo\Bar
  562. */
  563. public function help_test() {}
  564. protected function setUp() {}
  565. /**
  566. * I depend on the database function, but i already
  567. * had test in my name and a docblock
  568. *
  569. * @depends database
  570. */
  571. public function testDepends () {}
  572. }',
  573. ['case' => 'snake'],
  574. ],
  575. 'Test Annotation has to be removed, but its just one line' => [
  576. '<?php
  577. class Test extends \PhpUnit\FrameWork\TestCase
  578. {
  579. /** */
  580. public function testItWorks() {}
  581. }',
  582. '<?php
  583. class Test extends \PhpUnit\FrameWork\TestCase
  584. {
  585. /** @test */
  586. public function itWorks() {}
  587. }',
  588. ],
  589. 'Test annotation has to be added, but there is already a one line doc block' => [
  590. '<?php
  591. class Test extends \PhpUnit\FrameWork\TestCase
  592. {
  593. /**
  594. * @group Database
  595. *
  596. * @test
  597. */
  598. public function itTestsDatabase() {}
  599. }',
  600. '<?php
  601. class Test extends \PhpUnit\FrameWork\TestCase
  602. {
  603. /** @group Database */
  604. public function testItTestsDatabase() {}
  605. }',
  606. ['style' => 'annotation'],
  607. ],
  608. 'Test annotation has to be added, but there is already a one line doc block which is a sentence' => [
  609. '<?php
  610. class Test extends \PhpUnit\FrameWork\TestCase
  611. {
  612. /**
  613. * I really like this test, it helps a lot
  614. *
  615. * @test
  616. */
  617. public function itTestsDatabase() {}
  618. }',
  619. '<?php
  620. class Test extends \PhpUnit\FrameWork\TestCase
  621. {
  622. /** I really like this test, it helps a lot */
  623. public function testItTestsDatabase() {}
  624. }',
  625. ['style' => 'annotation'],
  626. ],
  627. 'Test annotation has to be added, but there is already a one line comment present' => [
  628. '<?php
  629. class Test extends \PhpUnit\FrameWork\TestCase
  630. {
  631. //I really like this test, it helps a lot
  632. /**
  633. * @test
  634. */
  635. public function itTestsDatabase() {}
  636. }',
  637. '<?php
  638. class Test extends \PhpUnit\FrameWork\TestCase
  639. {
  640. //I really like this test, it helps a lot
  641. public function testItTestsDatabase() {}
  642. }',
  643. ['style' => 'annotation'],
  644. ],
  645. 'Test annotation has to be added, there is a one line doc block which is an @depends tag' => [
  646. '<?php
  647. class Test extends \PhpUnit\FrameWork\TestCase
  648. {
  649. /**
  650. * @test
  651. */
  652. public function itTestsDatabase() {}
  653. /**
  654. * @depends itTestsDatabase
  655. *
  656. * @test
  657. */
  658. public function itDepends() {}
  659. }',
  660. '<?php
  661. class Test extends \PhpUnit\FrameWork\TestCase
  662. {
  663. public function testItTestsDatabase() {}
  664. /** @depends testItTestsDatabase */
  665. public function testItDepends() {}
  666. }',
  667. ['style' => 'annotation'],
  668. ],
  669. 'Annotation gets removed, but the function has a @testWith' => [
  670. '<?php
  671. final class ProcessLinterProcessBuilderTest extends TestCase
  672. {
  673. /**
  674. *
  675. * @param string $executable
  676. * @param string $file
  677. * @param string $expected
  678. *
  679. * @testWith ["php", "foo.php", "\"php\" -l \"foo.php\""]
  680. * ["C:\\Program Files\\php\\php.exe", "foo bar\\baz.php", "\"C:\\Program Files\\php\\php.exe\" -l \"foo bar\\baz.php\""]
  681. * @requires OS Linux|Darwin
  682. */
  683. public function testPrepareCommandOnPhpOnLinuxOrMac($executable, $file, $expected)
  684. {
  685. $builder = new ProcessLinterProcessBuilder($executable);
  686. $this->assertSame(
  687. $expected,
  688. $builder->build($file)->getCommandLine()
  689. );
  690. }
  691. }',
  692. '<?php
  693. final class ProcessLinterProcessBuilderTest extends TestCase
  694. {
  695. /**
  696. * @test
  697. * @param string $executable
  698. * @param string $file
  699. * @param string $expected
  700. *
  701. * @testWith ["php", "foo.php", "\"php\" -l \"foo.php\""]
  702. * ["C:\\Program Files\\php\\php.exe", "foo bar\\baz.php", "\"C:\\Program Files\\php\\php.exe\" -l \"foo bar\\baz.php\""]
  703. * @requires OS Linux|Darwin
  704. */
  705. public function prepareCommandOnPhpOnLinuxOrMac($executable, $file, $expected)
  706. {
  707. $builder = new ProcessLinterProcessBuilder($executable);
  708. $this->assertSame(
  709. $expected,
  710. $builder->build($file)->getCommandLine()
  711. );
  712. }
  713. }',
  714. ],
  715. 'Annotation gets added, but there is already an @testWith in the doc block' => [
  716. '<?php
  717. final class ProcessLinterProcessBuilderTest extends TestCase
  718. {
  719. /**
  720. * @param string $executable
  721. * @param string $file
  722. * @param string $expected
  723. *
  724. * @testWith ["php", "foo.php", "\"php\" -l \"foo.php\""]
  725. * ["C:\\Program Files\\php\\php.exe", "foo bar\\baz.php", "\"C:\\Program Files\\php\\php.exe\" -l \"foo bar\\baz.php\""]
  726. * @requires OS Linux|Darwin
  727. *
  728. * @test
  729. */
  730. public function prepareCommandOnPhpOnLinuxOrMac($executable, $file, $expected)
  731. {
  732. $builder = new ProcessLinterProcessBuilder($executable);
  733. $this->assertSame(
  734. $expected,
  735. $builder->build($file)->getCommandLine()
  736. );
  737. }
  738. }',
  739. '<?php
  740. final class ProcessLinterProcessBuilderTest extends TestCase
  741. {
  742. /**
  743. * @param string $executable
  744. * @param string $file
  745. * @param string $expected
  746. *
  747. * @testWith ["php", "foo.php", "\"php\" -l \"foo.php\""]
  748. * ["C:\\Program Files\\php\\php.exe", "foo bar\\baz.php", "\"C:\\Program Files\\php\\php.exe\" -l \"foo bar\\baz.php\""]
  749. * @requires OS Linux|Darwin
  750. */
  751. public function testPrepareCommandOnPhpOnLinuxOrMac($executable, $file, $expected)
  752. {
  753. $builder = new ProcessLinterProcessBuilder($executable);
  754. $this->assertSame(
  755. $expected,
  756. $builder->build($file)->getCommandLine()
  757. );
  758. }
  759. }',
  760. ['style' => 'annotation'],
  761. ],
  762. 'Annotation gets properly removed, even when it is in a weird place' => [
  763. '<?php
  764. class Test extends \PhpUnit\FrameWork\TestCase
  765. {
  766. /**
  767. * Im a comment about the function
  768. */
  769. public function testIHateMyTestSuite() {}
  770. /**
  771. * Im another comment about a function
  772. */
  773. public function testThisMakesNoSense() {}
  774. /**
  775. * This comment has more issues
  776. */
  777. public function testItUsesTabs() {}
  778. /**
  779. * @depends testItUsesTabs
  780. */
  781. public function testItDependsReally() {}
  782. /**
  783. * @depends testItUsesTabs
  784. */
  785. public function testItDependsSomeMore() {}
  786. }',
  787. '<?php
  788. class Test extends \PhpUnit\FrameWork\TestCase
  789. {
  790. /**
  791. * Im a comment @test about the function
  792. */
  793. public function iHateMyTestSuite() {}
  794. /**
  795. * Im another comment about a function @test
  796. */
  797. public function thisMakesNoSense() {}
  798. /**
  799. * This comment has @test more issues
  800. */
  801. public function itUsesTabs() {}
  802. /**
  803. * @depends itUsesTabs @test
  804. */
  805. public function itDependsReally() {}
  806. /**
  807. * @test @depends itUsesTabs
  808. */
  809. public function itDependsSomeMore() {}
  810. }',
  811. ],
  812. 'Annotation gets added when a single line has doc block has multiple tags already' => [
  813. '<?php
  814. class Test extends \PhpUnit\FrameWork\TestCase
  815. {
  816. /**
  817. * There is some text here @group Database @group Integration
  818. *
  819. * @test
  820. */
  821. public function whyDoThis() {}
  822. }',
  823. '<?php
  824. class Test extends \PhpUnit\FrameWork\TestCase
  825. {
  826. /** There is some text here @group Database @group Integration */
  827. public function testWhyDoThis() {}
  828. }',
  829. ['style' => 'annotation'],
  830. ],
  831. 'Annotation gets removed when a single line doc block has the tag, but there are other things as well' => [
  832. '<?php
  833. class Test extends \PhpUnit\FrameWork\TestCase
  834. {
  835. /** There is some text here @group Database @group Integration */
  836. public function testWhyDoThis() {}
  837. }',
  838. '<?php
  839. class Test extends \PhpUnit\FrameWork\TestCase
  840. {
  841. /** There is some @test text here @group Database @group Integration */
  842. public function testWhyDoThis() {}
  843. }',
  844. ],
  845. 'Annotation is used, and should be' => [
  846. '<?php
  847. class Test extends \PhpUnit\FrameWork\TestCase
  848. {
  849. /**
  850. * @test
  851. */
  852. public function itDoesSomething() {}
  853. }',
  854. null,
  855. ['style' => 'annotation'],
  856. ],
  857. 'Annotation is not used, and should not be' => [
  858. '<?php
  859. class Test extends \PhpUnit\FrameWork\TestCase
  860. {
  861. public function testItDoesSomething() {}
  862. }',
  863. ],
  864. 'Annotation is added when it is already present in a weird place' => [
  865. '<?php
  866. class Test extends \PhpUnit\FrameWork\TestCase
  867. {
  868. /**
  869. * Im a comment @test about the function
  870. *
  871. * @test
  872. */
  873. public function iHateMyTestSuite() {}
  874. }',
  875. '<?php
  876. class Test extends \PhpUnit\FrameWork\TestCase
  877. {
  878. /**
  879. * Im a comment @test about the function
  880. */
  881. public function iHateMyTestSuite() {}
  882. }',
  883. ['style' => 'annotation'],
  884. ],
  885. 'Docblock does not get converted to a multi line doc block if it already has @test annotation' => [
  886. '<?php
  887. class Test extends \PhpUnit\FrameWork\TestCase
  888. {
  889. /** @test */
  890. public function doesSomeThings() {}
  891. }',
  892. null,
  893. ['style' => 'annotation'],
  894. ],
  895. 'Annotation does not get added if class is not a test' => [
  896. '<?php
  897. class Waterloo
  898. {
  899. public function testDoesSomeThings() {}
  900. }',
  901. null,
  902. ['style' => 'annotation'],
  903. ],
  904. 'Annotation does not get removed if class is not a test' => [
  905. '<?php
  906. class Waterloo
  907. {
  908. /**
  909. * @test
  910. */
  911. public function doesSomeThings() {}
  912. }',
  913. ],
  914. 'Annotation does not get added if there are no tests in the test class' => [
  915. '<?php
  916. class Test extends \PhpUnit\FrameWork\TestCase
  917. {
  918. public function setUp() {}
  919. public function itHelpsSomeTests() {}
  920. public function someMoreChanges() {}
  921. }',
  922. null,
  923. ['style' => 'annotation'],
  924. ],
  925. 'Abstract test gets annotation removed' => [
  926. '<?php
  927. abstract class Test extends \PhpUnit\FrameWork\TestCase
  928. {
  929. /**
  930. *
  931. */
  932. abstract function testFooBar();
  933. }',
  934. '<?php
  935. abstract class Test extends \PhpUnit\FrameWork\TestCase
  936. {
  937. /**
  938. * @test
  939. */
  940. abstract function fooBar();
  941. }',
  942. ['style' => 'prefix'],
  943. ],
  944. 'Abstract test gets annotation added' => [
  945. '<?php
  946. abstract class Test extends \PhpUnit\FrameWork\TestCase
  947. {
  948. /**
  949. * @test
  950. */
  951. abstract function fooBar();
  952. }',
  953. '<?php
  954. abstract class Test extends \PhpUnit\FrameWork\TestCase
  955. {
  956. abstract function testFooBar();
  957. }',
  958. ['style' => 'annotation'],
  959. ],
  960. 'Annotation gets added, but there is a number after the testprefix so it keeps the prefix' => [
  961. '<?php
  962. class Test extends \PhpUnit\FrameWork\TestCase
  963. {
  964. /**
  965. * @test
  966. */
  967. public function test123fooBar() {}
  968. }',
  969. '<?php
  970. class Test extends \PhpUnit\FrameWork\TestCase
  971. {
  972. public function test123fooBar() {}
  973. }',
  974. ['style' => 'annotation'],
  975. ],
  976. ];
  977. }
  978. /**
  979. * @param string $expected
  980. * @param null|string $input
  981. * @param null|array $config
  982. *
  983. * @dataProvider provideMessyWhitespacesCases
  984. */
  985. public function testMessyWhitespaces($expected, $input = null, array $config = [])
  986. {
  987. $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n"));
  988. $this->fixer->configure($config);
  989. $this->doTest($expected, $input);
  990. }
  991. public function provideMessyWhitespacesCases()
  992. {
  993. return [
  994. [
  995. '<?php
  996. class FooTest extends \PHPUnit_Framework_TestCase {
  997. /**
  998. *
  999. */
  1000. public function testFooTest() {}
  1001. }
  1002. ',
  1003. '<?php
  1004. class FooTest extends \PHPUnit_Framework_TestCase {
  1005. /**
  1006. * @test
  1007. */
  1008. public function fooTest() {}
  1009. }
  1010. ',
  1011. ],
  1012. ];
  1013. }
  1014. }