PhpdocSeparationFixerTest.php 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  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 Graham Campbell <hello@gjcampbell.co.uk>
  17. * @author Jakub Kwaśniewski <jakub@zero-85.pl>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocSeparationFixer
  22. *
  23. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Phpdoc\PhpdocSeparationFixer>
  24. *
  25. * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Phpdoc\PhpdocSeparationFixer
  26. */
  27. final class PhpdocSeparationFixerTest extends AbstractFixerTestCase
  28. {
  29. public function testFix(): void
  30. {
  31. $this->doTest('<?php
  32. /** @param EngineInterface $templating
  33. *@return void
  34. */');
  35. $expected = <<<'EOF'
  36. <?php
  37. /**
  38. * @param EngineInterface $templating
  39. *
  40. * @return void
  41. */
  42. EOF;
  43. $input = <<<'EOF'
  44. <?php
  45. /**
  46. * @param EngineInterface $templating
  47. * @return void
  48. */
  49. EOF;
  50. $this->doTest($expected, $input);
  51. }
  52. public function testFixMoreTags(): void
  53. {
  54. $expected = <<<'EOF'
  55. <?php
  56. /**
  57. * Hello there!
  58. *
  59. * @internal
  60. *
  61. * @param string $foo
  62. *
  63. * @throws Exception
  64. *
  65. * @return bool
  66. */
  67. EOF;
  68. $input = <<<'EOF'
  69. <?php
  70. /**
  71. * Hello there!
  72. * @internal
  73. * @param string $foo
  74. * @throws Exception
  75. *
  76. *
  77. *
  78. * @return bool
  79. */
  80. EOF;
  81. $this->doTest($expected, $input);
  82. }
  83. public function testFixSpreadOut(): void
  84. {
  85. $expected = <<<'EOF'
  86. <?php
  87. /**
  88. * Hello there!
  89. *
  90. * Long description
  91. * goes here.
  92. *
  93. * @param string $foo
  94. * @param bool $bar Bar
  95. *
  96. * @throws Exception|RuntimeException
  97. *
  98. * @return bool
  99. */
  100. EOF;
  101. $input = <<<'EOF'
  102. <?php
  103. /**
  104. * Hello there!
  105. *
  106. * Long description
  107. * goes here.
  108. * @param string $foo
  109. *
  110. *
  111. * @param bool $bar Bar
  112. *
  113. *
  114. *
  115. * @throws Exception|RuntimeException
  116. *
  117. *
  118. *
  119. *
  120. * @return bool
  121. */
  122. EOF;
  123. $this->doTest($expected, $input);
  124. }
  125. public function testMultiLineComments(): void
  126. {
  127. $expected = <<<'EOF'
  128. <?php
  129. /**
  130. * Hello there!
  131. *
  132. * Long description
  133. * goes here.
  134. *
  135. * @param string $foo test 123
  136. * asdasdasd
  137. * @param bool $bar qwerty
  138. *
  139. * @throws Exception|RuntimeException
  140. *
  141. * @return bool
  142. */
  143. EOF;
  144. $input = <<<'EOF'
  145. <?php
  146. /**
  147. * Hello there!
  148. *
  149. * Long description
  150. * goes here.
  151. * @param string $foo test 123
  152. * asdasdasd
  153. * @param bool $bar qwerty
  154. * @throws Exception|RuntimeException
  155. * @return bool
  156. */
  157. EOF;
  158. $this->doTest($expected, $input);
  159. }
  160. public function testCrazyMultiLineComments(): void
  161. {
  162. $expected = <<<'EOF'
  163. <?php
  164. /**
  165. * Clients accept an array of constructor parameters.
  166. *
  167. * Here's an example of creating a client using a URI template for the
  168. * client's base_url and an array of default request options to apply
  169. * to each request:
  170. *
  171. * $client = new Client([
  172. * 'base_url' => [
  173. * 'https://www.foo.com/{version}/',
  174. * ['version' => '123']
  175. * ],
  176. * 'defaults' => [
  177. * 'timeout' => 10,
  178. * 'allow_redirects' => false,
  179. * 'proxy' => '192.168.16.1:10'
  180. * ]
  181. * ]);
  182. *
  183. * @param _AutogeneratedInputConfiguration $config Client configuration settings
  184. * - base_url: Base URL of the client that is merged into relative URLs.
  185. * Can be a string or an array that contains a URI template followed
  186. * by an associative array of expansion variables to inject into the
  187. * URI template.
  188. * - handler: callable RingPHP handler used to transfer requests
  189. * - message_factory: Factory used to create request and response object
  190. * - defaults: Default request options to apply to each request
  191. * - emitter: Event emitter used for request events
  192. * - fsm: (internal use only) The request finite state machine. A
  193. * function that accepts a transaction and optional final state. The
  194. * function is responsible for transitioning a request through its
  195. * lifecycle events.
  196. * @param string $foo
  197. */
  198. EOF;
  199. $this->doTest($expected);
  200. }
  201. public function testDoctrineExample(): void
  202. {
  203. $expected = <<<'EOF'
  204. <?php
  205. /**
  206. * PersistentObject base class that implements getter/setter methods for all mapped fields and associations
  207. * by overriding __call.
  208. *
  209. * This class is a forward compatible implementation of the PersistentObject trait.
  210. *
  211. * Limitations:
  212. *
  213. * 1. All persistent objects have to be associated with a single ObjectManager, multiple
  214. * ObjectManagers are not supported. You can set the ObjectManager with `PersistentObject#setObjectManager()`.
  215. * 2. Setters and getters only work if a ClassMetadata instance was injected into the PersistentObject.
  216. * This is either done on `postLoad` of an object or by accessing the global object manager.
  217. * 3. There are no hooks for setters/getters. Just implement the method yourself instead of relying on __call().
  218. * 4. Slower than handcoded implementations: An average of 7 method calls per access to a field and 11 for an association.
  219. * 5. Only the inverse side associations get autoset on the owning side as well. Setting objects on the owning side
  220. * will not set the inverse side associations.
  221. *
  222. * @example
  223. *
  224. * PersistentObject::setObjectManager($em);
  225. *
  226. * class Foo extends PersistentObject
  227. * {
  228. * private $id;
  229. * }
  230. *
  231. * $foo = new Foo();
  232. * $foo->getId(); // method exists through __call
  233. *
  234. * @author Benjamin Eberlei <kontakt@beberlei.de>
  235. */
  236. EOF;
  237. $this->doTest($expected);
  238. }
  239. public function testSymfonyExample(): void
  240. {
  241. $expected = <<<'EOF'
  242. <?php
  243. /**
  244. * Constructor.
  245. *
  246. * Depending on how you want the storage driver to behave you probably
  247. * want to override this constructor entirely.
  248. *
  249. * List of options for $options array with their defaults.
  250. *
  251. * @see https://php.net/session.configuration for options
  252. *
  253. * but we omit 'session.' from the beginning of the keys for convenience.
  254. *
  255. * ("auto_start", is not supported as it tells PHP to start a session before
  256. * PHP starts to execute user-land code. Setting during runtime has no effect).
  257. *
  258. * cache_limiter, "nocache" (use "0" to prevent headers from being sent entirely).
  259. * cookie_domain, ""
  260. * cookie_httponly, ""
  261. * cookie_lifetime, "0"
  262. * cookie_path, "/"
  263. * cookie_secure, ""
  264. * entropy_file, ""
  265. * entropy_length, "0"
  266. * gc_divisor, "100"
  267. * gc_maxlifetime, "1440"
  268. * gc_probability, "1"
  269. * hash_bits_per_character, "4"
  270. * hash_function, "0"
  271. * name, "PHPSESSID"
  272. * referer_check, ""
  273. * serialize_handler, "php"
  274. * use_cookies, "1"
  275. * use_only_cookies, "1"
  276. * use_trans_sid, "0"
  277. * upload_progress.enabled, "1"
  278. * upload_progress.cleanup, "1"
  279. * upload_progress.prefix, "upload_progress_"
  280. * upload_progress.name, "PHP_SESSION_UPLOAD_PROGRESS"
  281. * upload_progress.freq, "1%"
  282. * upload_progress.min-freq, "1"
  283. * url_rewriter.tags, "a=href,area=href,frame=src,form=,fieldset="
  284. *
  285. * @param array $options Session configuration options.
  286. * @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $handler
  287. * @param MetadataBag $metaBag MetadataBag.
  288. */
  289. EOF;
  290. $this->doTest($expected);
  291. }
  292. public function testDeprecatedAndSeeTags(): void
  293. {
  294. $expected = <<<'EOF'
  295. <?php
  296. /**
  297. * Hi!
  298. *
  299. * @author Bar Baz <foo@example.com>
  300. *
  301. * @deprecated As of some version.
  302. * @see Replacement
  303. * described here.
  304. *
  305. * @param string $foo test 123
  306. * @param bool $bar qwerty
  307. *
  308. * @return void
  309. */
  310. EOF;
  311. $input = <<<'EOF'
  312. <?php
  313. /**
  314. * Hi!
  315. *
  316. * @author Bar Baz <foo@example.com>
  317. * @deprecated As of some version.
  318. *
  319. * @see Replacement
  320. * described here.
  321. * @param string $foo test 123
  322. * @param bool $bar qwerty
  323. *
  324. * @return void
  325. */
  326. EOF;
  327. $this->doTest($expected, $input);
  328. }
  329. public function testPropertyTags(): void
  330. {
  331. $expected = <<<'EOF'
  332. <?php
  333. /**
  334. * @author Bar Baz <foo@example.com>
  335. *
  336. * @property int $foo
  337. * @property-read int $foo
  338. * @property-write int $bar
  339. */
  340. EOF;
  341. $input = <<<'EOF'
  342. <?php
  343. /**
  344. * @author Bar Baz <foo@example.com>
  345. * @property int $foo
  346. *
  347. * @property-read int $foo
  348. *
  349. * @property-write int $bar
  350. */
  351. EOF;
  352. $this->doTest($expected, $input);
  353. }
  354. public function testClassDocBlock(): void
  355. {
  356. $expected = <<<'EOF'
  357. <?php
  358. namespace Foo;
  359. /**
  360. * This is a class that does classy things.
  361. *
  362. * @internal
  363. *
  364. * @package Foo
  365. * @subpackage Foo\Bar
  366. *
  367. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  368. * @author Graham Campbell <hello@gjcampbell.co.uk>
  369. * @copyright Foo Bar
  370. * @license MIT
  371. */
  372. class Bar {}
  373. EOF;
  374. $input = <<<'EOF'
  375. <?php
  376. namespace Foo;
  377. /**
  378. * This is a class that does classy things.
  379. * @internal
  380. * @package Foo
  381. *
  382. *
  383. * @subpackage Foo\Bar
  384. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  385. *
  386. * @author Graham Campbell <hello@gjcampbell.co.uk>
  387. *
  388. * @copyright Foo Bar
  389. *
  390. *
  391. * @license MIT
  392. */
  393. class Bar {}
  394. EOF;
  395. $this->doTest($expected, $input);
  396. }
  397. public function testPoorAlignment(): void
  398. {
  399. $expected = <<<'EOF'
  400. <?php
  401. namespace Foo;
  402. /**
  403. * This is a class that does classy things.
  404. *
  405. * @internal
  406. *
  407. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  408. *@author Graham Campbell <hello@gjcampbell.co.uk>
  409. */
  410. class Bar {}
  411. EOF;
  412. $input = <<<'EOF'
  413. <?php
  414. namespace Foo;
  415. /**
  416. * This is a class that does classy things.
  417. *
  418. * @internal
  419. *
  420. *
  421. *
  422. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  423. *
  424. *
  425. *@author Graham Campbell <hello@gjcampbell.co.uk>
  426. */
  427. class Bar {}
  428. EOF;
  429. $this->doTest($expected, $input);
  430. }
  431. public function testMoveUnknownAnnotations(): void
  432. {
  433. $expected = <<<'EOF'
  434. <?php
  435. /**
  436. * @expectedException Exception
  437. *
  438. * @expectedExceptionMessage Oh Noes!
  439. * Something when wrong!
  440. *
  441. * @Hello\Test\Foo(asd)
  442. *
  443. * @Method("GET")
  444. *
  445. * @param string $expected
  446. * @param string $input
  447. */
  448. EOF;
  449. $input = <<<'EOF'
  450. <?php
  451. /**
  452. * @expectedException Exception
  453. * @expectedExceptionMessage Oh Noes!
  454. * Something when wrong!
  455. *
  456. *
  457. * @Hello\Test\Foo(asd)
  458. * @Method("GET")
  459. *
  460. * @param string $expected
  461. *
  462. * @param string $input
  463. */
  464. EOF;
  465. $this->doTest($expected, $input);
  466. }
  467. /**
  468. * @dataProvider provideInheritDocCases
  469. */
  470. public function testInheritDoc(string $expected, string $input): void
  471. {
  472. $this->doTest($expected, $input);
  473. }
  474. /**
  475. * @return iterable<array{string, string}>
  476. */
  477. public static function provideInheritDocCases(): iterable
  478. {
  479. yield [
  480. '<?php
  481. /**
  482. * {@inheritdoc}
  483. *
  484. * @param string $expected
  485. * @param string $input
  486. */
  487. ',
  488. '<?php
  489. /**
  490. * {@inheritdoc}
  491. * @param string $expected
  492. * @param string $input
  493. */
  494. ',
  495. ];
  496. yield [
  497. '<?php
  498. /**
  499. * {@inheritDoc}
  500. *
  501. * @param string $expected
  502. * @param string $input
  503. */
  504. ',
  505. '<?php
  506. /**
  507. * {@inheritDoc}
  508. * @param string $expected
  509. * @param string $input
  510. */
  511. ',
  512. ];
  513. }
  514. public function testEmptyDocBlock(): void
  515. {
  516. $expected = <<<'EOF'
  517. <?php
  518. /**
  519. *
  520. */
  521. EOF;
  522. $this->doTest($expected);
  523. }
  524. public function testLargerEmptyDocBlock(): void
  525. {
  526. $expected = <<<'EOF'
  527. <?php
  528. /**
  529. *
  530. *
  531. *
  532. *
  533. */
  534. EOF;
  535. $this->doTest($expected);
  536. }
  537. public function testOneLineDocBlock(): void
  538. {
  539. $expected = <<<'EOF'
  540. <?php
  541. /** Foo */
  542. const Foo = 1;
  543. EOF;
  544. $this->doTest($expected);
  545. }
  546. public function testMessyWhitespaces(): void
  547. {
  548. $expected = "<?php\t/**\r\n\t * @param string \$text\r\n\t *\r\n\t * @return string\r\n\t */";
  549. $input = "<?php\t/**\r\n\t * @param string \$text\r\n\t * @return string\r\n\t */";
  550. $this->doTest($expected, $input);
  551. }
  552. public function testWithSpacing(): void
  553. {
  554. $expected = '<?php
  555. /**
  556. * Foo
  557. *
  558. * @bar 123
  559. *
  560. * {@inheritdoc} '.'
  561. *
  562. * @param string $expected
  563. * @param string $input
  564. */';
  565. $input = '<?php
  566. /**
  567. * Foo
  568. * @bar 123
  569. *
  570. * {@inheritdoc} '.'
  571. * @param string $expected
  572. * @param string $input
  573. */';
  574. $this->doTest($expected, $input);
  575. }
  576. public function testTagInTwoGroupsConfiguration(): void
  577. {
  578. $this->expectException(InvalidFixerConfigurationException::class);
  579. $this->expectExceptionMessage(
  580. 'The option "groups" value is invalid. '.
  581. 'The "param" tag belongs to more than one group.'
  582. );
  583. $this->fixer->configure(['groups' => [['param', 'return'], ['param', 'throws']]]);
  584. }
  585. public function testTagSpecifiedTwoTimesInGroupConfiguration(): void
  586. {
  587. $this->expectException(InvalidFixerConfigurationException::class);
  588. $this->expectExceptionMessage(
  589. 'The option "groups" value is invalid. '.
  590. 'The "param" tag is specified more than once.'
  591. );
  592. $this->fixer->configure(['groups' => [['param', 'return', 'param', 'throws']]]);
  593. }
  594. public function testLaravelGroups(): void
  595. {
  596. $this->fixer->configure(['groups' => [
  597. ['param', 'return'],
  598. ['throws'],
  599. ['deprecated', 'link', 'see', 'since'],
  600. ['author', 'copyright', 'license'],
  601. ['category', 'package', 'subpackage'],
  602. ['property', 'property-read', 'property-write'],
  603. ]]);
  604. $expected = <<<'EOF'
  605. <?php
  606. /**
  607. * Attempt to authenticate using HTTP Basic Auth.
  608. *
  609. * @param string $field
  610. * @param array $extraConditions
  611. * @return \Symfony\Component\HttpFoundation\Response|null
  612. *
  613. * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
  614. */
  615. EOF;
  616. $input = <<<'EOF'
  617. <?php
  618. /**
  619. * Attempt to authenticate using HTTP Basic Auth.
  620. *
  621. * @param string $field
  622. * @param array $extraConditions
  623. * @return \Symfony\Component\HttpFoundation\Response|null
  624. * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
  625. */
  626. EOF;
  627. $this->doTest($expected, $input);
  628. }
  629. public function testVariousGroups(): void
  630. {
  631. $this->fixer->configure([
  632. 'groups' => [
  633. ['deprecated', 'link', 'see', 'since', 'author', 'copyright', 'license'],
  634. ['category', 'package', 'subpackage'],
  635. ['property', 'property-read', 'property-write'],
  636. ['return', 'param'],
  637. ],
  638. ]);
  639. $expected = <<<'EOF'
  640. <?php
  641. /**
  642. * Attempt to authenticate using HTTP Basic Auth.
  643. *
  644. * @link https://example.com/link
  645. * @see https://doc.example.com/link
  646. * @copyright by John Doe 2001
  647. * @author John Doe
  648. *
  649. * @property-custom string $prop
  650. *
  651. * @param string $field
  652. * @param array $extraConditions
  653. * @return \Symfony\Component\HttpFoundation\Response|null
  654. *
  655. * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
  656. */
  657. EOF;
  658. $input = <<<'EOF'
  659. <?php
  660. /**
  661. * Attempt to authenticate using HTTP Basic Auth.
  662. *
  663. * @link https://example.com/link
  664. *
  665. *
  666. * @see https://doc.example.com/link
  667. * @copyright by John Doe 2001
  668. * @author John Doe
  669. * @property-custom string $prop
  670. * @param string $field
  671. * @param array $extraConditions
  672. *
  673. * @return \Symfony\Component\HttpFoundation\Response|null
  674. * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
  675. */
  676. EOF;
  677. $this->doTest($expected, $input);
  678. }
  679. public function testVariousAdditionalGroups(): void
  680. {
  681. $this->fixer->configure([
  682. 'groups' => [
  683. ['deprecated', 'link', 'see', 'since', 'author', 'copyright', 'license'],
  684. ['category', 'package', 'subpackage'],
  685. ['property', 'property-read', 'property-write'],
  686. ['return', 'param'],
  687. ],
  688. ]);
  689. $expected = <<<'EOF'
  690. <?php
  691. /**
  692. * Attempt to authenticate using HTTP Basic Auth.
  693. *
  694. * @link https://example.com/link
  695. * @see https://doc.example.com/link
  696. * @copyright by John Doe 2001
  697. * @author John Doe
  698. *
  699. * @param string $field
  700. * @param array $extraConditions
  701. * @return \Symfony\Component\HttpFoundation\Response|null
  702. *
  703. * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
  704. */
  705. EOF;
  706. $input = <<<'EOF'
  707. <?php
  708. /**
  709. * Attempt to authenticate using HTTP Basic Auth.
  710. *
  711. * @link https://example.com/link
  712. *
  713. *
  714. * @see https://doc.example.com/link
  715. * @copyright by John Doe 2001
  716. * @author John Doe
  717. * @param string $field
  718. * @param array $extraConditions
  719. *
  720. * @return \Symfony\Component\HttpFoundation\Response|null
  721. * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
  722. */
  723. EOF;
  724. $this->doTest($expected, $input);
  725. }
  726. /**
  727. * @dataProvider provideDocCodeCases
  728. *
  729. * @param _AutogeneratedInputConfiguration $config
  730. */
  731. public function testDocCode(string $expected, ?string $input = null, ?array $config = null): void
  732. {
  733. if (null !== $config) {
  734. $this->fixer->configure($config);
  735. }
  736. $this->doTest($expected, $input);
  737. }
  738. /**
  739. * @return iterable<string, array{0: string, 1?: string, 2?: array<string, mixed>}>
  740. */
  741. public static function provideDocCodeCases(): iterable
  742. {
  743. $input = <<<'EOF'
  744. <?php
  745. /**
  746. * Hello there!
  747. *
  748. * @author John Doe
  749. * @custom Test!
  750. * @throws Exception|RuntimeException foo
  751. * @param string $foo
  752. * @param bool $bar Bar
  753. *
  754. * @return int Return the number of changes.
  755. */
  756. EOF;
  757. yield 'laravel' => [
  758. <<<'EOF'
  759. <?php
  760. /**
  761. * Hello there!
  762. *
  763. * @author John Doe
  764. *
  765. * @custom Test!
  766. *
  767. * @throws Exception|RuntimeException foo
  768. *
  769. * @param string $foo
  770. * @param bool $bar Bar
  771. * @return int Return the number of changes.
  772. */
  773. EOF,
  774. $input,
  775. ['groups' => [
  776. ['param', 'return'],
  777. ['throws'],
  778. ['deprecated', 'link', 'see', 'since'],
  779. ['author', 'copyright', 'license'],
  780. ['category', 'package', 'subpackage'],
  781. ['property', 'property-read', 'property-write'],
  782. ]],
  783. ];
  784. yield 'all_tags' => [
  785. <<<'EOF'
  786. <?php
  787. /**
  788. * Hello there!
  789. *
  790. * @author John Doe
  791. * @custom Test!
  792. * @throws Exception|RuntimeException foo
  793. *
  794. * @param string $foo
  795. * @param bool $bar Bar
  796. * @return int Return the number of changes.
  797. */
  798. EOF,
  799. $input,
  800. ['groups' => [['author', 'throws', 'custom'], ['return', 'param']]],
  801. ];
  802. yield 'default_groups_standard_tags' => [
  803. <<<'EOF'
  804. <?php
  805. /**
  806. * Hello there!
  807. *
  808. * @author John Doe
  809. *
  810. * @throws Exception|RuntimeException foo
  811. *
  812. * @custom Test!
  813. *
  814. * @param string $foo
  815. * @param bool $bar Bar
  816. *
  817. * @return int Return the number of changes.
  818. */
  819. EOF,
  820. <<<'EOF'
  821. <?php
  822. /**
  823. * Hello there!
  824. * @author John Doe
  825. * @throws Exception|RuntimeException foo
  826. * @custom Test!
  827. * @param string $foo
  828. * @param bool $bar Bar
  829. * @return int Return the number of changes.
  830. */
  831. EOF,
  832. ];
  833. yield 'Separated unlisted tags with default config' => [
  834. <<<'EOF'
  835. <?php
  836. /**
  837. * @not-in-any-group1
  838. *
  839. * @not-in-any-group2
  840. *
  841. * @not-in-any-group3
  842. */
  843. EOF,
  844. <<<'EOF'
  845. <?php
  846. /**
  847. * @not-in-any-group1
  848. * @not-in-any-group2
  849. * @not-in-any-group3
  850. */
  851. EOF,
  852. ];
  853. yield 'Skip unlisted tags' => [
  854. <<<'EOF'
  855. <?php
  856. /**
  857. * @in-group-1
  858. * @in-group-1-too
  859. *
  860. * @not-in-any-group1
  861. *
  862. * @not-in-any-group2
  863. * @not-in-any-group3
  864. */
  865. EOF,
  866. <<<'EOF'
  867. <?php
  868. /**
  869. * @in-group-1
  870. *
  871. * @in-group-1-too
  872. * @not-in-any-group1
  873. *
  874. * @not-in-any-group2
  875. * @not-in-any-group3
  876. */
  877. EOF,
  878. [
  879. 'groups' => [['in-group-1', 'in-group-1-too']],
  880. 'skip_unlisted_annotations' => true,
  881. ],
  882. ];
  883. yield 'Doctrine annotations' => [
  884. <<<'EOF'
  885. <?php
  886. /**
  887. * @ORM\Id
  888. * @ORM\Column(type="integer")
  889. * @ORM\GeneratedValue
  890. */
  891. EOF,
  892. <<<'EOF'
  893. <?php
  894. /**
  895. * @ORM\Id
  896. *
  897. * @ORM\Column(type="integer")
  898. *
  899. * @ORM\GeneratedValue
  900. */
  901. EOF,
  902. ['groups' => [
  903. ['ORM\Id', 'ORM\Column', 'ORM\GeneratedValue'],
  904. ]],
  905. ];
  906. yield 'With wildcard' => [
  907. <<<'EOF'
  908. <?php
  909. /**
  910. * @ORM\Id
  911. * @ORM\Column(type="integer")
  912. * @ORM\GeneratedValue
  913. *
  914. * @Assert\NotNull
  915. * @Assert\Type("string")
  916. */
  917. EOF,
  918. <<<'EOF'
  919. <?php
  920. /**
  921. * @ORM\Id
  922. *
  923. * @ORM\Column(type="integer")
  924. *
  925. * @ORM\GeneratedValue
  926. * @Assert\NotNull
  927. *
  928. * @Assert\Type("string")
  929. */
  930. EOF,
  931. ['groups' => [
  932. ['ORM\*'],
  933. ['Assert\*'],
  934. ]],
  935. ];
  936. }
  937. }