PhpdocSeparationFixerTest.php 22 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  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(): array
  471. {
  472. return [
  473. [
  474. '<?php
  475. /**
  476. * {@inheritdoc}
  477. *
  478. * @param string $expected
  479. * @param string $input
  480. */
  481. ',
  482. '<?php
  483. /**
  484. * {@inheritdoc}
  485. * @param string $expected
  486. * @param string $input
  487. */
  488. ',
  489. ],
  490. [
  491. '<?php
  492. /**
  493. * {@inheritDoc}
  494. *
  495. * @param string $expected
  496. * @param string $input
  497. */
  498. ',
  499. '<?php
  500. /**
  501. * {@inheritDoc}
  502. * @param string $expected
  503. * @param string $input
  504. */
  505. ',
  506. ],
  507. ];
  508. }
  509. public function testEmptyDocBlock(): void
  510. {
  511. $expected = <<<'EOF'
  512. <?php
  513. /**
  514. *
  515. */
  516. EOF;
  517. $this->doTest($expected);
  518. }
  519. public function testLargerEmptyDocBlock(): void
  520. {
  521. $expected = <<<'EOF'
  522. <?php
  523. /**
  524. *
  525. *
  526. *
  527. *
  528. */
  529. EOF;
  530. $this->doTest($expected);
  531. }
  532. public function testOneLineDocBlock(): void
  533. {
  534. $expected = <<<'EOF'
  535. <?php
  536. /** Foo */
  537. const Foo = 1;
  538. EOF;
  539. $this->doTest($expected);
  540. }
  541. public function testMessyWhitespaces(): void
  542. {
  543. $expected = "<?php\t/**\r\n\t * @param string \$text\r\n\t *\r\n\t * @return string\r\n\t */";
  544. $input = "<?php\t/**\r\n\t * @param string \$text\r\n\t * @return string\r\n\t */";
  545. $this->doTest($expected, $input);
  546. }
  547. public function testWithSpacing(): void
  548. {
  549. $expected = '<?php
  550. /**
  551. * Foo
  552. *
  553. * @bar 123
  554. *
  555. * {@inheritdoc} '.'
  556. *
  557. * @param string $expected
  558. * @param string $input
  559. */';
  560. $input = '<?php
  561. /**
  562. * Foo
  563. * @bar 123
  564. *
  565. * {@inheritdoc} '.'
  566. * @param string $expected
  567. * @param string $input
  568. */';
  569. $this->doTest($expected, $input);
  570. }
  571. public function testTagInTwoGroupsConfiguration(): void
  572. {
  573. $this->expectException(InvalidFixerConfigurationException::class);
  574. $this->expectExceptionMessage(
  575. 'The option "groups" value is invalid. '.
  576. 'The "param" tag belongs to more than one group.'
  577. );
  578. $this->fixer->configure(['groups' => [['param', 'return'], ['param', 'throws']]]);
  579. }
  580. public function testTagSpecifiedTwoTimesInGroupConfiguration(): void
  581. {
  582. $this->expectException(InvalidFixerConfigurationException::class);
  583. $this->expectExceptionMessage(
  584. 'The option "groups" value is invalid. '.
  585. 'The "param" tag is specified more than once.'
  586. );
  587. $this->fixer->configure(['groups' => [['param', 'return', 'param', 'throws']]]);
  588. }
  589. public function testLaravelGroups(): void
  590. {
  591. $this->fixer->configure(['groups' => [
  592. ['param', 'return'],
  593. ['throws'],
  594. ['deprecated', 'link', 'see', 'since'],
  595. ['author', 'copyright', 'license'],
  596. ['category', 'package', 'subpackage'],
  597. ['property', 'property-read', 'property-write'],
  598. ]]);
  599. $expected = <<<'EOF'
  600. <?php
  601. /**
  602. * Attempt to authenticate using HTTP Basic Auth.
  603. *
  604. * @param string $field
  605. * @param array $extraConditions
  606. * @return \Symfony\Component\HttpFoundation\Response|null
  607. *
  608. * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
  609. */
  610. EOF;
  611. $input = <<<'EOF'
  612. <?php
  613. /**
  614. * Attempt to authenticate using HTTP Basic Auth.
  615. *
  616. * @param string $field
  617. * @param array $extraConditions
  618. * @return \Symfony\Component\HttpFoundation\Response|null
  619. * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
  620. */
  621. EOF;
  622. $this->doTest($expected, $input);
  623. }
  624. public function testVariousGroups(): void
  625. {
  626. $this->fixer->configure([
  627. 'groups' => [
  628. ['deprecated', 'link', 'see', 'since', 'author', 'copyright', 'license'],
  629. ['category', 'package', 'subpackage'],
  630. ['property', 'property-read', 'property-write'],
  631. ['return', 'param'],
  632. ],
  633. ]);
  634. $expected = <<<'EOF'
  635. <?php
  636. /**
  637. * Attempt to authenticate using HTTP Basic Auth.
  638. *
  639. * @link https://example.com/link
  640. * @see https://doc.example.com/link
  641. * @copyright by John Doe 2001
  642. * @author John Doe
  643. *
  644. * @property-custom string $prop
  645. *
  646. * @param string $field
  647. * @param array $extraConditions
  648. * @return \Symfony\Component\HttpFoundation\Response|null
  649. *
  650. * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
  651. */
  652. EOF;
  653. $input = <<<'EOF'
  654. <?php
  655. /**
  656. * Attempt to authenticate using HTTP Basic Auth.
  657. *
  658. * @link https://example.com/link
  659. *
  660. *
  661. * @see https://doc.example.com/link
  662. * @copyright by John Doe 2001
  663. * @author John Doe
  664. * @property-custom string $prop
  665. * @param string $field
  666. * @param array $extraConditions
  667. *
  668. * @return \Symfony\Component\HttpFoundation\Response|null
  669. * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
  670. */
  671. EOF;
  672. $this->doTest($expected, $input);
  673. }
  674. public function testVariousAdditionalGroups(): void
  675. {
  676. $this->fixer->configure([
  677. 'groups' => [
  678. ['deprecated', 'link', 'see', 'since', 'author', 'copyright', 'license'],
  679. ['category', 'package', 'subpackage'],
  680. ['property', 'property-read', 'property-write'],
  681. ['return', 'param'],
  682. ],
  683. ]);
  684. $expected = <<<'EOF'
  685. <?php
  686. /**
  687. * Attempt to authenticate using HTTP Basic Auth.
  688. *
  689. * @link https://example.com/link
  690. * @see https://doc.example.com/link
  691. * @copyright by John Doe 2001
  692. * @author John Doe
  693. *
  694. * @param string $field
  695. * @param array $extraConditions
  696. * @return \Symfony\Component\HttpFoundation\Response|null
  697. *
  698. * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
  699. */
  700. EOF;
  701. $input = <<<'EOF'
  702. <?php
  703. /**
  704. * Attempt to authenticate using HTTP Basic Auth.
  705. *
  706. * @link https://example.com/link
  707. *
  708. *
  709. * @see https://doc.example.com/link
  710. * @copyright by John Doe 2001
  711. * @author John Doe
  712. * @param string $field
  713. * @param array $extraConditions
  714. *
  715. * @return \Symfony\Component\HttpFoundation\Response|null
  716. * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
  717. */
  718. EOF;
  719. $this->doTest($expected, $input);
  720. }
  721. /**
  722. * @dataProvider provideDocCodeCases
  723. *
  724. * @param array<string, mixed> $config
  725. */
  726. public function testDocCode(string $expected, ?string $input = null, ?array $config = null): void
  727. {
  728. if (null !== $config) {
  729. $this->fixer->configure($config);
  730. }
  731. $this->doTest($expected, $input);
  732. }
  733. /**
  734. * @return array<array<null|array<string, mixed>|string>>
  735. */
  736. public static function provideDocCodeCases(): iterable
  737. {
  738. $input = <<<'EOF'
  739. <?php
  740. /**
  741. * Hello there!
  742. *
  743. * @author John Doe
  744. * @custom Test!
  745. * @throws Exception|RuntimeException foo
  746. * @param string $foo
  747. * @param bool $bar Bar
  748. *
  749. * @return int Return the number of changes.
  750. */
  751. EOF;
  752. yield 'laravel' => [
  753. <<<'EOF'
  754. <?php
  755. /**
  756. * Hello there!
  757. *
  758. * @author John Doe
  759. *
  760. * @custom Test!
  761. *
  762. * @throws Exception|RuntimeException foo
  763. *
  764. * @param string $foo
  765. * @param bool $bar Bar
  766. * @return int Return the number of changes.
  767. */
  768. EOF,
  769. $input,
  770. ['groups' => [
  771. ['param', 'return'],
  772. ['throws'],
  773. ['deprecated', 'link', 'see', 'since'],
  774. ['author', 'copyright', 'license'],
  775. ['category', 'package', 'subpackage'],
  776. ['property', 'property-read', 'property-write'],
  777. ]],
  778. ];
  779. yield 'all_tags' => [
  780. <<<'EOF'
  781. <?php
  782. /**
  783. * Hello there!
  784. *
  785. * @author John Doe
  786. * @custom Test!
  787. * @throws Exception|RuntimeException foo
  788. *
  789. * @param string $foo
  790. * @param bool $bar Bar
  791. * @return int Return the number of changes.
  792. */
  793. EOF,
  794. $input,
  795. ['groups' => [['author', 'throws', 'custom'], ['return', 'param']]],
  796. ];
  797. yield 'default_groups_standard_tags' => [
  798. <<<'EOF'
  799. <?php
  800. /**
  801. * Hello there!
  802. *
  803. * @author John Doe
  804. *
  805. * @throws Exception|RuntimeException foo
  806. *
  807. * @custom Test!
  808. *
  809. * @param string $foo
  810. * @param bool $bar Bar
  811. *
  812. * @return int Return the number of changes.
  813. */
  814. EOF,
  815. <<<'EOF'
  816. <?php
  817. /**
  818. * Hello there!
  819. * @author John Doe
  820. * @throws Exception|RuntimeException foo
  821. * @custom Test!
  822. * @param string $foo
  823. * @param bool $bar Bar
  824. * @return int Return the number of changes.
  825. */
  826. EOF,
  827. ];
  828. yield 'default_groups_all_tags' => [
  829. <<<'EOF'
  830. <?php
  831. /**
  832. * Hello there!
  833. *
  834. * @author John Doe
  835. *
  836. * @throws Exception|RuntimeException foo
  837. *
  838. * @custom Test!
  839. *
  840. * @param string $foo
  841. * @param bool $bar Bar
  842. *
  843. * @return int Return the number of changes.
  844. */
  845. EOF,
  846. <<<'EOF'
  847. <?php
  848. /**
  849. * Hello there!
  850. * @author John Doe
  851. * @throws Exception|RuntimeException foo
  852. * @custom Test!
  853. * @param string $foo
  854. * @param bool $bar Bar
  855. * @return int Return the number of changes.
  856. */
  857. EOF,
  858. ];
  859. yield 'Separated unlisted tags with default config' => [
  860. <<<'EOF'
  861. <?php
  862. /**
  863. * @not-in-any-group1
  864. *
  865. * @not-in-any-group2
  866. *
  867. * @not-in-any-group3
  868. */
  869. EOF,
  870. <<<'EOF'
  871. <?php
  872. /**
  873. * @not-in-any-group1
  874. * @not-in-any-group2
  875. * @not-in-any-group3
  876. */
  877. EOF,
  878. ];
  879. yield 'Skip unlisted tags' => [
  880. <<<'EOF'
  881. <?php
  882. /**
  883. * @in-group-1
  884. * @in-group-1-too
  885. *
  886. * @not-in-any-group1
  887. *
  888. * @not-in-any-group2
  889. * @not-in-any-group3
  890. */
  891. EOF,
  892. <<<'EOF'
  893. <?php
  894. /**
  895. * @in-group-1
  896. *
  897. * @in-group-1-too
  898. * @not-in-any-group1
  899. *
  900. * @not-in-any-group2
  901. * @not-in-any-group3
  902. */
  903. EOF,
  904. [
  905. 'groups' => [['in-group-1', 'in-group-1-too']],
  906. 'skip_unlisted_annotations' => true,
  907. ],
  908. ];
  909. yield 'Doctrine annotations' => [
  910. <<<'EOF'
  911. <?php
  912. /**
  913. * @ORM\Id
  914. * @ORM\Column(type="integer")
  915. * @ORM\GeneratedValue
  916. */
  917. EOF,
  918. <<<'EOF'
  919. <?php
  920. /**
  921. * @ORM\Id
  922. *
  923. * @ORM\Column(type="integer")
  924. *
  925. * @ORM\GeneratedValue
  926. */
  927. EOF,
  928. ['groups' => [
  929. ['ORM\Id', 'ORM\Column', 'ORM\GeneratedValue'],
  930. ]],
  931. ];
  932. yield 'With wildcard' => [
  933. <<<'EOF'
  934. <?php
  935. /**
  936. * @ORM\Id
  937. * @ORM\Column(type="integer")
  938. * @ORM\GeneratedValue
  939. *
  940. * @Assert\NotNull
  941. * @Assert\Type("string")
  942. */
  943. EOF,
  944. <<<'EOF'
  945. <?php
  946. /**
  947. * @ORM\Id
  948. *
  949. * @ORM\Column(type="integer")
  950. *
  951. * @ORM\GeneratedValue
  952. * @Assert\NotNull
  953. *
  954. * @Assert\Type("string")
  955. */
  956. EOF,
  957. ['groups' => [
  958. ['ORM\*'],
  959. ['Assert\*'],
  960. ]],
  961. ];
  962. }
  963. }