PhpdocSeparationFixerTest.php 30 KB

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