DoctrineAnnotationBracesFixerTest.php 7.4 KB

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