DoctrineAnnotationIndentationFixerTest.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\Fixer\DoctrineAnnotation;
  12. use PhpCsFixer\Tests\AbstractDoctrineAnnotationFixerTestCase;
  13. /**
  14. * @internal
  15. *
  16. * @covers \PhpCsFixer\AbstractDoctrineAnnotationFixer
  17. * @covers \PhpCsFixer\Fixer\DoctrineAnnotation\DoctrineAnnotationIndentationFixer
  18. */
  19. final class DoctrineAnnotationIndentationFixerTest extends AbstractDoctrineAnnotationFixerTestCase
  20. {
  21. /**
  22. * @param string $expected
  23. * @param null|string $input
  24. *
  25. * @dataProvider provideFixCases
  26. */
  27. public function testFix($expected, $input = null)
  28. {
  29. $this->doTest($expected, $input);
  30. }
  31. /**
  32. * @param string $expected
  33. * @param null|string $input
  34. *
  35. * @dataProvider provideFixCases
  36. */
  37. public function testFixWithUnindentedMixedLines($expected, $input = null)
  38. {
  39. $this->fixer->configure([
  40. 'indent_mixed_lines' => false,
  41. ]);
  42. $this->doTest($expected, $input);
  43. }
  44. /**
  45. * @return array
  46. */
  47. public function provideFixCases()
  48. {
  49. return $this->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. /**
  326. * @param string $expected
  327. * @param null|string $input
  328. *
  329. * @dataProvider provideFixWithIndentedMixedLinesCases
  330. */
  331. public function testFixWithIndentedMixedLines($expected, $input = null)
  332. {
  333. $this->fixer->configure([
  334. 'indent_mixed_lines' => true,
  335. ]);
  336. $this->doTest($expected, $input);
  337. }
  338. /**
  339. * @return array
  340. */
  341. public function provideFixWithIndentedMixedLinesCases()
  342. {
  343. return $this->createTestCases([
  344. ['
  345. /**
  346. * Foo.
  347. *
  348. * @author John Doe
  349. *
  350. * @Foo
  351. * @Bar
  352. */', '
  353. /**
  354. * Foo.
  355. *
  356. * @author John Doe
  357. *
  358. * @Foo
  359. * @Bar
  360. */'],
  361. ['
  362. /**
  363. * @Foo(
  364. * foo="foo"
  365. * )
  366. */', '
  367. /**
  368. * @Foo(
  369. * foo="foo"
  370. * )
  371. */'],
  372. ['
  373. /**
  374. * @Foo(foo="foo", bar={
  375. * "foo": 1,
  376. * "foobar": 2,
  377. * "foobarbaz": 3
  378. * })
  379. */', '
  380. /**
  381. * @Foo(foo="foo", bar={
  382. * "foo": 1,
  383. * "foobar": 2,
  384. * "foobarbaz": 3
  385. * })
  386. */'],
  387. ['
  388. /**
  389. * @Foo(@Bar({
  390. * "FOO": 1,
  391. * "BAR": 2,
  392. * "BAZ": 3
  393. * }))
  394. */', '
  395. /**
  396. * @Foo(@Bar({
  397. * "FOO": 1,
  398. * "BAR": 2,
  399. * "BAZ": 3
  400. * }))
  401. */'],
  402. ['
  403. /**
  404. * @Foo(
  405. * @Bar({
  406. * "FOO": 1,
  407. * "BAR": 2,
  408. * "BAZ": 3
  409. * })
  410. * )
  411. */', '
  412. /**
  413. * @Foo(
  414. * @Bar({
  415. * "FOO": 1,
  416. * "BAR": 2,
  417. * "BAZ": 3
  418. * })
  419. * )
  420. */'],
  421. ['
  422. /**
  423. * @Foo(
  424. * @Bar(
  425. * "baz"
  426. * )
  427. */'],
  428. ['
  429. /**
  430. * Foo(
  431. * Bar()
  432. * "baz"
  433. * )
  434. */'],
  435. ['
  436. /**
  437. * @Foo( @Bar(
  438. * "baz"
  439. * ) )
  440. */', '
  441. /**
  442. * @Foo( @Bar(
  443. * "baz"
  444. * ) )
  445. */'],
  446. ['
  447. /**
  448. * @Foo(x={
  449. * @Bar
  450. * })
  451. * @Foo\z
  452. */', '
  453. /**
  454. * @Foo(x={
  455. * @Bar
  456. * })
  457. * @Foo\z
  458. */'],
  459. ['
  460. /**
  461. * Description with a single " character.
  462. *
  463. * @Foo(
  464. * "string "" with inner quote"
  465. * )
  466. *
  467. * @param mixed description with a single " character.
  468. */', '
  469. /**
  470. * Description with a single " character.
  471. *
  472. * @Foo(
  473. * "string "" with inner quote"
  474. * )
  475. *
  476. * @param mixed description with a single " character.
  477. */'],
  478. ['
  479. /**
  480. * @Foo(@Bar,
  481. * @Baz)
  482. * @Qux
  483. */', '
  484. /**
  485. * @Foo(@Bar,
  486. * @Baz)
  487. * @Qux
  488. */'],
  489. ['
  490. /**
  491. * @Foo({"bar",
  492. * "baz"})
  493. * @Qux
  494. */', '
  495. /**
  496. * @Foo({"bar",
  497. * "baz"})
  498. * @Qux
  499. */'],
  500. ['
  501. /**
  502. * // PHPDocumentor 1
  503. * @abstract
  504. * @access
  505. * @code
  506. * @deprec
  507. * @encode
  508. * @exception
  509. * @final
  510. * @ingroup
  511. * @inheritdoc
  512. * @inheritDoc
  513. * @magic
  514. * @name
  515. * @toc
  516. * @tutorial
  517. * @private
  518. * @static
  519. * @staticvar
  520. * @staticVar
  521. * @throw
  522. *
  523. * // PHPDocumentor 2
  524. * @api
  525. * @author
  526. * @category
  527. * @copyright
  528. * @deprecated
  529. * @example
  530. * @filesource
  531. * @global
  532. * @ignore
  533. * @internal
  534. * @license
  535. * @link
  536. * @method
  537. * @package
  538. * @param
  539. * @property
  540. * @property-read
  541. * @property-write
  542. * @return
  543. * @see
  544. * @since
  545. * @source
  546. * @subpackage
  547. * @throws
  548. * @todo
  549. * @TODO
  550. * @usedBy
  551. * @uses
  552. * @var
  553. * @version
  554. *
  555. * // PHPUnit
  556. * @after
  557. * @afterClass
  558. * @backupGlobals
  559. * @backupStaticAttributes
  560. * @before
  561. * @beforeClass
  562. * @codeCoverageIgnore
  563. * @codeCoverageIgnoreStart
  564. * @codeCoverageIgnoreEnd
  565. * @covers
  566. * @coversDefaultClass
  567. * @coversNothing
  568. * @dataProvider
  569. * @depends
  570. * @expectedException
  571. * @expectedExceptionCode
  572. * @expectedExceptionMessage
  573. * @expectedExceptionMessageRegExp
  574. * @group
  575. * @large
  576. * @medium
  577. * @preserveGlobalState
  578. * @requires
  579. * @runTestsInSeparateProcesses
  580. * @runInSeparateProcess
  581. * @small
  582. * @test
  583. * @testdox
  584. * @ticket
  585. * @uses
  586. *
  587. * // PHPCheckStyle
  588. * @SuppressWarnings
  589. *
  590. * // PHPStorm
  591. * @noinspection
  592. *
  593. * // PEAR
  594. * @package_version
  595. *
  596. * // PlantUML
  597. * @enduml
  598. * @startuml
  599. *
  600. * // other
  601. * @fix
  602. * @FIXME
  603. * @fixme
  604. * @override
  605. */'],
  606. ['
  607. /**
  608. * @Foo({
  609. * @Bar()}
  610. * )
  611. */'],
  612. ]);
  613. }
  614. }