DoctrineAnnotationIndentationFixerTest.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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\DoctrineAnnotation;
  13. use PhpCsFixer\Tests\AbstractDoctrineAnnotationFixerTestCase;
  14. /**
  15. * @internal
  16. *
  17. * @covers \PhpCsFixer\AbstractDoctrineAnnotationFixer
  18. * @covers \PhpCsFixer\Doctrine\Annotation\DocLexer
  19. * @covers \PhpCsFixer\Fixer\DoctrineAnnotation\DoctrineAnnotationIndentationFixer
  20. *
  21. * @extends AbstractDoctrineAnnotationFixerTestCase<\PhpCsFixer\Fixer\DoctrineAnnotation\DoctrineAnnotationIndentationFixer>
  22. *
  23. * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\DoctrineAnnotation\DoctrineAnnotationIndentationFixer
  24. */
  25. final class DoctrineAnnotationIndentationFixerTest extends AbstractDoctrineAnnotationFixerTestCase
  26. {
  27. /**
  28. * @dataProvider provideFixCases
  29. */
  30. public function testFix(string $expected, ?string $input = null): void
  31. {
  32. $this->doTest($expected, $input);
  33. }
  34. /**
  35. * @dataProvider provideFixCases
  36. */
  37. public function testFixWithUnindentedMixedLines(string $expected, ?string $input = null): void
  38. {
  39. $this->fixer->configure([
  40. 'indent_mixed_lines' => false,
  41. ]);
  42. $this->doTest($expected, $input);
  43. }
  44. /**
  45. * @return iterable<array{0: string, 1?: null|string}>
  46. */
  47. public static function provideFixCases(): iterable
  48. {
  49. yield from self::createTestCases([
  50. ['
  51. /**
  52. * Foo.
  53. *
  54. * @author John Doe
  55. *
  56. * @Foo
  57. * @Bar
  58. */', '
  59. /**
  60. * Foo.
  61. *
  62. * @author John Doe
  63. *
  64. * @Foo
  65. * @Bar
  66. */'],
  67. ['
  68. /**
  69. * @Foo(
  70. * foo="foo"
  71. * )
  72. */', '
  73. /**
  74. * @Foo(
  75. * foo="foo"
  76. * )
  77. */'],
  78. ['
  79. /**
  80. * @Foo(foo="foo", bar={
  81. * "foo": 1,
  82. * "foobar": 2,
  83. * "foobarbaz": 3
  84. * })
  85. */', '
  86. /**
  87. * @Foo(foo="foo", bar={
  88. * "foo": 1,
  89. * "foobar": 2,
  90. * "foobarbaz": 3
  91. * })
  92. */'],
  93. ['
  94. /**
  95. * @Foo(@Bar({
  96. * "FOO": 1,
  97. * "BAR": 2,
  98. * "BAZ": 3
  99. * }))
  100. */', '
  101. /**
  102. * @Foo(@Bar({
  103. * "FOO": 1,
  104. * "BAR": 2,
  105. * "BAZ": 3
  106. * }))
  107. */'],
  108. ['
  109. /**
  110. * @Foo(
  111. * @Bar({
  112. * "FOO": 1,
  113. * "BAR": 2,
  114. * "BAZ": 3
  115. * })
  116. * )
  117. */', '
  118. /**
  119. * @Foo(
  120. * @Bar({
  121. * "FOO": 1,
  122. * "BAR": 2,
  123. * "BAZ": 3
  124. * })
  125. * )
  126. */'],
  127. ['
  128. /**
  129. * @Foo(
  130. * @Bar(
  131. * "baz"
  132. * )
  133. */'],
  134. ['
  135. /**
  136. * Foo(
  137. * Bar()
  138. * "baz"
  139. * )
  140. */'],
  141. ['
  142. /**
  143. * @Foo( @Bar(
  144. * "baz"
  145. * ) )
  146. */', '
  147. /**
  148. * @Foo( @Bar(
  149. * "baz"
  150. * ) )
  151. */'],
  152. ['
  153. /**
  154. * @Foo(x={
  155. * @Bar
  156. * })
  157. * @Foo\z
  158. */', '
  159. /**
  160. * @Foo(x={
  161. * @Bar
  162. * })
  163. * @Foo\z
  164. */'],
  165. ['
  166. /**
  167. * Description with a single " character.
  168. *
  169. * @Foo(
  170. * "string "" with inner quote"
  171. * )
  172. *
  173. * @param mixed description with a single " character.
  174. */', '
  175. /**
  176. * Description with a single " character.
  177. *
  178. * @Foo(
  179. * "string "" with inner quote"
  180. * )
  181. *
  182. * @param mixed description with a single " character.
  183. */'],
  184. ['
  185. /**
  186. * @Foo(@Bar,
  187. * @Baz)
  188. * @Qux
  189. */', '
  190. /**
  191. * @Foo(@Bar,
  192. * @Baz)
  193. * @Qux
  194. */'],
  195. ['
  196. /**
  197. * @Foo({"bar",
  198. * "baz"})
  199. * @Qux
  200. */', '
  201. /**
  202. * @Foo({"bar",
  203. * "baz"})
  204. * @Qux
  205. */'],
  206. ['
  207. /**
  208. * // PHPDocumentor 1
  209. * @abstract
  210. * @access
  211. * @code
  212. * @deprec
  213. * @encode
  214. * @exception
  215. * @final
  216. * @ingroup
  217. * @inheritdoc
  218. * @inheritDoc
  219. * @magic
  220. * @name
  221. * @toc
  222. * @tutorial
  223. * @private
  224. * @static
  225. * @staticvar
  226. * @staticVar
  227. * @throw
  228. *
  229. * // PHPDocumentor 2
  230. * @api
  231. * @author
  232. * @category
  233. * @copyright
  234. * @deprecated
  235. * @example
  236. * @filesource
  237. * @global
  238. * @ignore
  239. * @internal
  240. * @license
  241. * @link
  242. * @method
  243. * @package
  244. * @param
  245. * @property
  246. * @property-read
  247. * @property-write
  248. * @return
  249. * @see
  250. * @since
  251. * @source
  252. * @subpackage
  253. * @throws
  254. * @todo
  255. * @TODO
  256. * @usedBy
  257. * @uses
  258. * @var
  259. * @version
  260. *
  261. * // PHPUnit
  262. * @after
  263. * @afterClass
  264. * @backupGlobals
  265. * @backupStaticAttributes
  266. * @before
  267. * @beforeClass
  268. * @codeCoverageIgnore
  269. * @codeCoverageIgnoreStart
  270. * @codeCoverageIgnoreEnd
  271. * @covers
  272. * @coversDefaultClass
  273. * @coversNothing
  274. * @dataProvider
  275. * @depends
  276. * @expectedException
  277. * @expectedExceptionCode
  278. * @expectedExceptionMessage
  279. * @expectedExceptionMessageRegExp
  280. * @group
  281. * @large
  282. * @medium
  283. * @preserveGlobalState
  284. * @requires
  285. * @runTestsInSeparateProcesses
  286. * @runInSeparateProcess
  287. * @small
  288. * @test
  289. * @testdox
  290. * @ticket
  291. * @uses
  292. *
  293. * // PHPCheckStyle
  294. * @SuppressWarnings
  295. *
  296. * // PHPStorm
  297. * @noinspection
  298. *
  299. * // PEAR
  300. * @package_version
  301. *
  302. * // PlantUML
  303. * @enduml
  304. * @startuml
  305. *
  306. * // other
  307. * @fix
  308. * @FIXME
  309. * @fixme
  310. * @override
  311. */'],
  312. ['
  313. /**
  314. * @Foo({
  315. * @Bar()}
  316. * )
  317. */', '
  318. /**
  319. * @Foo({
  320. * @Bar()}
  321. * )
  322. */'],
  323. ['
  324. /**
  325. * @Foo(foo={
  326. * "bar": 1,
  327. * }, baz={
  328. * "qux": 2,
  329. * })
  330. */
  331. '],
  332. ['
  333. /**
  334. * @Foo(foo={
  335. * "foo",
  336. * }, bar={ "bar" }, baz={
  337. * "baz"
  338. * })
  339. */
  340. '],
  341. ]);
  342. yield [
  343. '<?php
  344. /**
  345. * @see \User getId()
  346. */
  347. ',
  348. ];
  349. }
  350. /**
  351. * @dataProvider provideFixWithIndentedMixedLinesCases
  352. */
  353. public function testFixWithIndentedMixedLines(string $expected, ?string $input = null): void
  354. {
  355. $this->fixer->configure([
  356. 'indent_mixed_lines' => true,
  357. ]);
  358. $this->doTest($expected, $input);
  359. }
  360. /**
  361. * @return iterable<array{0: string, 1?: null|string}>
  362. */
  363. public static function provideFixWithIndentedMixedLinesCases(): iterable
  364. {
  365. yield from self::createTestCases([
  366. ['
  367. /**
  368. * Foo.
  369. *
  370. * @author John Doe
  371. *
  372. * @Foo
  373. * @Bar
  374. */', '
  375. /**
  376. * Foo.
  377. *
  378. * @author John Doe
  379. *
  380. * @Foo
  381. * @Bar
  382. */'],
  383. ['
  384. /**
  385. * @Foo(
  386. * foo="foo"
  387. * )
  388. */', '
  389. /**
  390. * @Foo(
  391. * foo="foo"
  392. * )
  393. */'],
  394. ['
  395. /**
  396. * @Foo(foo="foo", bar={
  397. * "foo": 1,
  398. * "foobar": 2,
  399. * "foobarbaz": 3
  400. * })
  401. */', '
  402. /**
  403. * @Foo(foo="foo", bar={
  404. * "foo": 1,
  405. * "foobar": 2,
  406. * "foobarbaz": 3
  407. * })
  408. */'],
  409. ['
  410. /**
  411. * @Foo(@Bar({
  412. * "FOO": 1,
  413. * "BAR": 2,
  414. * "BAZ": 3
  415. * }))
  416. */', '
  417. /**
  418. * @Foo(@Bar({
  419. * "FOO": 1,
  420. * "BAR": 2,
  421. * "BAZ": 3
  422. * }))
  423. */'],
  424. ['
  425. /**
  426. * @Foo(
  427. * @Bar({
  428. * "FOO": 1,
  429. * "BAR": 2,
  430. * "BAZ": 3
  431. * })
  432. * )
  433. */', '
  434. /**
  435. * @Foo(
  436. * @Bar({
  437. * "FOO": 1,
  438. * "BAR": 2,
  439. * "BAZ": 3
  440. * })
  441. * )
  442. */'],
  443. ['
  444. /**
  445. * @Foo(
  446. * @Bar(
  447. * "baz"
  448. * )
  449. */'],
  450. ['
  451. /**
  452. * Foo(
  453. * Bar()
  454. * "baz"
  455. * )
  456. */'],
  457. ['
  458. /**
  459. * @Foo( @Bar(
  460. * "baz"
  461. * ) )
  462. */', '
  463. /**
  464. * @Foo( @Bar(
  465. * "baz"
  466. * ) )
  467. */'],
  468. ['
  469. /**
  470. * @Foo(x={
  471. * @Bar
  472. * })
  473. * @Foo\z
  474. */', '
  475. /**
  476. * @Foo(x={
  477. * @Bar
  478. * })
  479. * @Foo\z
  480. */'],
  481. ['
  482. /**
  483. * Description with a single " character.
  484. *
  485. * @Foo(
  486. * "string "" with inner quote"
  487. * )
  488. *
  489. * @param mixed description with a single " character.
  490. */', '
  491. /**
  492. * Description with a single " character.
  493. *
  494. * @Foo(
  495. * "string "" with inner quote"
  496. * )
  497. *
  498. * @param mixed description with a single " character.
  499. */'],
  500. ['
  501. /**
  502. * @Foo(@Bar,
  503. * @Baz)
  504. * @Qux
  505. */', '
  506. /**
  507. * @Foo(@Bar,
  508. * @Baz)
  509. * @Qux
  510. */'],
  511. ['
  512. /**
  513. * @Foo({"bar",
  514. * "baz"})
  515. * @Qux
  516. */', '
  517. /**
  518. * @Foo({"bar",
  519. * "baz"})
  520. * @Qux
  521. */'],
  522. ['
  523. /**
  524. * // PHPDocumentor 1
  525. * @abstract
  526. * @access
  527. * @code
  528. * @deprec
  529. * @encode
  530. * @exception
  531. * @final
  532. * @ingroup
  533. * @inheritdoc
  534. * @inheritDoc
  535. * @magic
  536. * @name
  537. * @toc
  538. * @tutorial
  539. * @private
  540. * @static
  541. * @staticvar
  542. * @staticVar
  543. * @throw
  544. *
  545. * // PHPDocumentor 2
  546. * @api
  547. * @author
  548. * @category
  549. * @copyright
  550. * @deprecated
  551. * @example
  552. * @filesource
  553. * @global
  554. * @ignore
  555. * @internal
  556. * @license
  557. * @link
  558. * @method
  559. * @package
  560. * @param
  561. * @property
  562. * @property-read
  563. * @property-write
  564. * @return
  565. * @see
  566. * @since
  567. * @source
  568. * @subpackage
  569. * @throws
  570. * @todo
  571. * @TODO
  572. * @usedBy
  573. * @uses
  574. * @var
  575. * @version
  576. *
  577. * // PHPUnit
  578. * @after
  579. * @afterClass
  580. * @backupGlobals
  581. * @backupStaticAttributes
  582. * @before
  583. * @beforeClass
  584. * @codeCoverageIgnore
  585. * @codeCoverageIgnoreStart
  586. * @codeCoverageIgnoreEnd
  587. * @covers
  588. * @coversDefaultClass
  589. * @coversNothing
  590. * @dataProvider
  591. * @depends
  592. * @expectedException
  593. * @expectedExceptionCode
  594. * @expectedExceptionMessage
  595. * @expectedExceptionMessageRegExp
  596. * @group
  597. * @large
  598. * @medium
  599. * @preserveGlobalState
  600. * @requires
  601. * @runTestsInSeparateProcesses
  602. * @runInSeparateProcess
  603. * @small
  604. * @test
  605. * @testdox
  606. * @ticket
  607. * @uses
  608. *
  609. * // PHPCheckStyle
  610. * @SuppressWarnings
  611. *
  612. * // PHPStorm
  613. * @noinspection
  614. *
  615. * // PEAR
  616. * @package_version
  617. *
  618. * // PlantUML
  619. * @enduml
  620. * @startuml
  621. *
  622. * // other
  623. * @fix
  624. * @FIXME
  625. * @fixme
  626. * @override
  627. */'],
  628. ['
  629. /**
  630. * @Foo({
  631. * @Bar()}
  632. * )
  633. */'],
  634. ]);
  635. }
  636. }