DoctrineAnnotationIndentationFixerTest.php 9.1 KB

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