DoctrineAnnotationSpacesFixerTest.php 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  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\DoctrineAnnotationSpacesFixer
  18. */
  19. final class DoctrineAnnotationSpacesFixerTest extends AbstractDoctrineAnnotationFixerTestCase
  20. {
  21. /**
  22. * @param string $expected
  23. * @param string|null $input
  24. *
  25. * @dataProvider getFixAllCases
  26. */
  27. public function testFixAll($expected, $input = null)
  28. {
  29. $this->doTest($expected, $input);
  30. $this->fixer->configure([
  31. 'around_parentheses' => true,
  32. 'around_commas' => true,
  33. 'around_argument_assignments' => true,
  34. 'around_array_assignments' => true,
  35. ]);
  36. $this->doTest($expected, $input);
  37. }
  38. /**
  39. * @return array
  40. */
  41. public function getFixAllCases()
  42. {
  43. return $this->createTestCases([
  44. ['
  45. /**
  46. * @Foo
  47. */'],
  48. ['
  49. /**
  50. * @Foo()
  51. */'],
  52. ['
  53. /**
  54. * Foo.
  55. *
  56. * @author John Doe
  57. *
  58. * @Foo(foo="foo", bar="bar")
  59. */', '
  60. /**
  61. * Foo.
  62. *
  63. * @author John Doe
  64. *
  65. * @Foo ( foo = "foo" ,bar = "bar" )
  66. */'],
  67. ['
  68. /**
  69. * @Foo(
  70. * foo="foo",
  71. * bar="bar"
  72. * )
  73. */', '
  74. /**
  75. * @Foo (
  76. * foo = "foo" ,
  77. * bar = "bar"
  78. * )
  79. */'],
  80. ['
  81. /**
  82. * @Foo(
  83. * @Bar("foo", "bar"),
  84. * @Baz
  85. * )
  86. */', '
  87. /**
  88. * @Foo(
  89. * @Bar ( "foo" ,"bar") ,
  90. * @Baz
  91. * )
  92. */'],
  93. ['
  94. /**
  95. * @Foo({"bar", "baz"})
  96. */', '
  97. /**
  98. * @Foo( {"bar" ,"baz"} )
  99. */'],
  100. ['
  101. /**
  102. * @Foo(foo="=foo", bar={"foo" : "=foo", "bar" = "=bar"})
  103. */', '
  104. /**
  105. * @Foo(foo = "=foo" ,bar = {"foo" : "=foo", "bar"="=bar"})
  106. */'],
  107. [
  108. '/** @Foo(foo="foo", bar={"foo" : "foo", "bar" = "bar"}) */',
  109. '/** @Foo ( foo = "foo" ,bar = {"foo" : "foo", "bar"="bar"} ) */',
  110. ],
  111. ['
  112. /**
  113. * @Foo(
  114. * foo="foo",
  115. * bar={
  116. * "foo" : "foo",
  117. * "bar" = "bar"
  118. * }
  119. * )
  120. */', '
  121. /**
  122. * @Foo(
  123. * foo = "foo"
  124. * ,
  125. * bar = {
  126. * "foo":"foo",
  127. * "bar"="bar"
  128. * }
  129. * )
  130. */'],
  131. ['
  132. /**
  133. * @Foo(
  134. * foo="foo",
  135. * bar={
  136. * "foo" : "foo",
  137. * "bar" = "bar"
  138. * }
  139. * )
  140. */', '
  141. /**
  142. * @Foo
  143. * (
  144. * foo
  145. * =
  146. * "foo",
  147. * bar
  148. * =
  149. * {
  150. * "foo"
  151. * :
  152. * "foo",
  153. * "bar"
  154. * =
  155. * "bar"
  156. * }
  157. * )
  158. */'],
  159. ['
  160. /**
  161. * @Foo(foo="foo", "bar"=@Bar\Baz({"foo" : true, "bar" = false}))
  162. */', '
  163. /**
  164. * @Foo ( foo = "foo", "bar" = @Bar\Baz({"foo":true, "bar"=false}) )
  165. */'],
  166. ['
  167. /**
  168. * @Foo(foo = "foo" ,bar="bar"
  169. */'],
  170. ['
  171. /**
  172. * Comment , with a comma.
  173. */'],
  174. ['
  175. /**
  176. * Description with a single " character.
  177. *
  178. * @Foo(foo="string "" with inner quote", bar="string "" with inner quote")
  179. *
  180. * @param mixed description with a single " character.
  181. */', '
  182. /**
  183. * Description with a single " character.
  184. *
  185. * @Foo( foo="string "" with inner quote" ,bar="string "" with inner quote" )
  186. *
  187. * @param mixed description with a single " character.
  188. */'],
  189. ['
  190. /**
  191. * // PHPDocumentor 1
  192. * @abstract ( foo,bar = "baz" )
  193. * @access ( foo,bar = "baz" )
  194. * @code ( foo,bar = "baz" )
  195. * @deprec ( foo,bar = "baz" )
  196. * @encode ( foo,bar = "baz" )
  197. * @exception ( foo,bar = "baz" )
  198. * @final ( foo,bar = "baz" )
  199. * @ingroup ( foo,bar = "baz" )
  200. * @inheritdoc ( foo,bar = "baz" )
  201. * @inheritDoc ( foo,bar = "baz" )
  202. * @magic ( foo,bar = "baz" )
  203. * @name ( foo,bar = "baz" )
  204. * @toc ( foo,bar = "baz" )
  205. * @tutorial ( foo,bar = "baz" )
  206. * @private ( foo,bar = "baz" )
  207. * @static ( foo,bar = "baz" )
  208. * @staticvar ( foo,bar = "baz" )
  209. * @staticVar ( foo,bar = "baz" )
  210. * @throw ( foo,bar = "baz" )
  211. *
  212. * // PHPDocumentor 2
  213. * @api ( foo,bar = "baz" )
  214. * @author ( foo,bar = "baz" )
  215. * @category ( foo,bar = "baz" )
  216. * @copyright ( foo,bar = "baz" )
  217. * @deprecated ( foo,bar = "baz" )
  218. * @example ( foo,bar = "baz" )
  219. * @filesource ( foo,bar = "baz" )
  220. * @global ( foo,bar = "baz" )
  221. * @ignore ( foo,bar = "baz" )
  222. * @internal ( foo,bar = "baz" )
  223. * @license ( foo,bar = "baz" )
  224. * @link ( foo,bar = "baz" )
  225. * @method ( foo,bar = "baz" )
  226. * @package ( foo,bar = "baz" )
  227. * @param ( foo,bar = "baz" )
  228. * @property ( foo,bar = "baz" )
  229. * @property-read ( foo,bar = "baz" )
  230. * @property-write ( foo,bar = "baz" )
  231. * @return ( foo,bar = "baz" )
  232. * @see ( foo,bar = "baz" )
  233. * @since ( foo,bar = "baz" )
  234. * @source ( foo,bar = "baz" )
  235. * @subpackage ( foo,bar = "baz" )
  236. * @throws ( foo,bar = "baz" )
  237. * @todo ( foo,bar = "baz" )
  238. * @TODO ( foo,bar = "baz" )
  239. * @usedBy ( foo,bar = "baz" )
  240. * @uses ( foo,bar = "baz" )
  241. * @var ( foo,bar = "baz" )
  242. * @version ( foo,bar = "baz" )
  243. *
  244. * // PHPUnit
  245. * @after ( foo,bar = "baz" )
  246. * @afterClass ( foo,bar = "baz" )
  247. * @backupGlobals ( foo,bar = "baz" )
  248. * @backupStaticAttributes ( foo,bar = "baz" )
  249. * @before ( foo,bar = "baz" )
  250. * @beforeClass ( foo,bar = "baz" )
  251. * @codeCoverageIgnore ( foo,bar = "baz" )
  252. * @codeCoverageIgnoreStart ( foo,bar = "baz" )
  253. * @codeCoverageIgnoreEnd ( foo,bar = "baz" )
  254. * @covers ( foo,bar = "baz" )
  255. * @coversDefaultClass ( foo,bar = "baz" )
  256. * @coversNothing ( foo,bar = "baz" )
  257. * @dataProvider ( foo,bar = "baz" )
  258. * @depends ( foo,bar = "baz" )
  259. * @expectedException ( foo,bar = "baz" )
  260. * @expectedExceptionCode ( foo,bar = "baz" )
  261. * @expectedExceptionMessage ( foo,bar = "baz" )
  262. * @expectedExceptionMessageRegExp ( foo,bar = "baz" )
  263. * @group ( foo,bar = "baz" )
  264. * @large ( foo,bar = "baz" )
  265. * @medium ( foo,bar = "baz" )
  266. * @preserveGlobalState ( foo,bar = "baz" )
  267. * @requires ( foo,bar = "baz" )
  268. * @runTestsInSeparateProcesses ( foo,bar = "baz" )
  269. * @runInSeparateProcess ( foo,bar = "baz" )
  270. * @small ( foo,bar = "baz" )
  271. * @test ( foo,bar = "baz" )
  272. * @testdox ( foo,bar = "baz" )
  273. * @ticket ( foo,bar = "baz" )
  274. * @uses ( foo,bar = "baz" )
  275. *
  276. * // PHPCheckStyle
  277. * @SuppressWarnings ( foo,bar = "baz" )
  278. *
  279. * // PHPStorm
  280. * @noinspection ( foo,bar = "baz" )
  281. *
  282. * // PEAR
  283. * @package_version ( foo,bar = "baz" )
  284. *
  285. * // PlantUML
  286. * @enduml ( foo,bar = "baz" )
  287. * @startuml ( foo,bar = "baz" )
  288. *
  289. * // other
  290. * @fix ( foo,bar = "baz" )
  291. * @FIXME ( foo,bar = "baz" )
  292. * @fixme ( foo,bar = "baz" )
  293. * @override
  294. */'],
  295. ['
  296. /**
  297. * @Transform /^(\d+)$/
  298. */'],
  299. ]);
  300. }
  301. /**
  302. * @param string $expected
  303. * @param string|null $input
  304. *
  305. * @dataProvider getFixAroundParenthesesOnlyCases
  306. */
  307. public function testFixAroundParenthesesOnly($expected, $input = null)
  308. {
  309. $this->fixer->configure([
  310. 'around_commas' => false,
  311. 'around_argument_assignments' => false,
  312. 'around_array_assignments' => false,
  313. ]);
  314. $this->doTest($expected, $input);
  315. $this->fixer->configure([
  316. 'around_parentheses' => true,
  317. 'around_commas' => false,
  318. 'around_argument_assignments' => false,
  319. 'around_array_assignments' => false,
  320. ]);
  321. $this->doTest($expected, $input);
  322. }
  323. /**
  324. * @return array
  325. */
  326. public function getFixAroundParenthesesOnlyCases()
  327. {
  328. return $this->createTestCases([
  329. ['
  330. /**
  331. * @Foo
  332. */'],
  333. ['
  334. /**
  335. * Foo.
  336. *
  337. * @author John Doe
  338. *
  339. * @Foo()
  340. */', '
  341. /**
  342. * Foo.
  343. *
  344. * @author John Doe
  345. *
  346. * @Foo ( )
  347. */'],
  348. ['
  349. /**
  350. * @Foo("bar")
  351. */', '
  352. /**
  353. * @Foo( "bar" )
  354. */'],
  355. ['
  356. /**
  357. * @Foo("bar", "baz")
  358. */', '
  359. /**
  360. * @Foo( "bar", "baz" )
  361. */'],
  362. [
  363. '/** @Foo("bar", "baz") */',
  364. '/** @Foo( "bar", "baz" ) */',
  365. ],
  366. ['
  367. /**
  368. * @Foo("bar", "baz")
  369. */', '
  370. /**
  371. * @Foo( "bar", "baz" )
  372. */'],
  373. ['
  374. /**
  375. * @Foo("bar", "baz")
  376. */', '
  377. /**
  378. * @Foo ( "bar", "baz" )
  379. */'],
  380. ['
  381. /**
  382. * @Foo(
  383. * "bar",
  384. * "baz"
  385. * )
  386. */', '
  387. /**
  388. * @Foo
  389. * (
  390. * "bar",
  391. * "baz"
  392. * )
  393. */'],
  394. ['
  395. /**
  396. * @Foo(
  397. * @Bar("baz")
  398. * )
  399. */', '
  400. /**
  401. * @Foo
  402. * (
  403. * @Bar ( "baz" )
  404. * )
  405. */'],
  406. ['
  407. /**
  408. * @Foo ( @Bar ( "bar" )
  409. */'],
  410. ['
  411. /**
  412. * Foo ( Bar Baz )
  413. */'],
  414. ['
  415. /**
  416. * Description with a single " character.
  417. *
  418. * @Foo("string "" with inner quote")
  419. *
  420. * @param mixed description with a single " character.
  421. */', '
  422. /**
  423. * Description with a single " character.
  424. *
  425. * @Foo ( "string "" with inner quote" )
  426. *
  427. * @param mixed description with a single " character.
  428. */'],
  429. ['
  430. /**
  431. * // PHPDocumentor 1
  432. * @abstract ( foo,bar = "baz" )
  433. * @access ( foo,bar = "baz" )
  434. * @code ( foo,bar = "baz" )
  435. * @deprec ( foo,bar = "baz" )
  436. * @encode ( foo,bar = "baz" )
  437. * @exception ( foo,bar = "baz" )
  438. * @final ( foo,bar = "baz" )
  439. * @ingroup ( foo,bar = "baz" )
  440. * @inheritdoc ( foo,bar = "baz" )
  441. * @inheritDoc ( foo,bar = "baz" )
  442. * @magic ( foo,bar = "baz" )
  443. * @name ( foo,bar = "baz" )
  444. * @toc ( foo,bar = "baz" )
  445. * @tutorial ( foo,bar = "baz" )
  446. * @private ( foo,bar = "baz" )
  447. * @static ( foo,bar = "baz" )
  448. * @staticvar ( foo,bar = "baz" )
  449. * @staticVar ( foo,bar = "baz" )
  450. * @throw ( foo,bar = "baz" )
  451. *
  452. * // PHPDocumentor 2
  453. * @api ( foo,bar = "baz" )
  454. * @author ( foo,bar = "baz" )
  455. * @category ( foo,bar = "baz" )
  456. * @copyright ( foo,bar = "baz" )
  457. * @deprecated ( foo,bar = "baz" )
  458. * @example ( foo,bar = "baz" )
  459. * @filesource ( foo,bar = "baz" )
  460. * @global ( foo,bar = "baz" )
  461. * @ignore ( foo,bar = "baz" )
  462. * @internal ( foo,bar = "baz" )
  463. * @license ( foo,bar = "baz" )
  464. * @link ( foo,bar = "baz" )
  465. * @method ( foo,bar = "baz" )
  466. * @package ( foo,bar = "baz" )
  467. * @param ( foo,bar = "baz" )
  468. * @property ( foo,bar = "baz" )
  469. * @property-read ( foo,bar = "baz" )
  470. * @property-write ( foo,bar = "baz" )
  471. * @return ( foo,bar = "baz" )
  472. * @see ( foo,bar = "baz" )
  473. * @since ( foo,bar = "baz" )
  474. * @source ( foo,bar = "baz" )
  475. * @subpackage ( foo,bar = "baz" )
  476. * @throws ( foo,bar = "baz" )
  477. * @todo ( foo,bar = "baz" )
  478. * @TODO ( foo,bar = "baz" )
  479. * @usedBy ( foo,bar = "baz" )
  480. * @uses ( foo,bar = "baz" )
  481. * @var ( foo,bar = "baz" )
  482. * @version ( foo,bar = "baz" )
  483. *
  484. * // PHPUnit
  485. * @after ( foo,bar = "baz" )
  486. * @afterClass ( foo,bar = "baz" )
  487. * @backupGlobals ( foo,bar = "baz" )
  488. * @backupStaticAttributes ( foo,bar = "baz" )
  489. * @before ( foo,bar = "baz" )
  490. * @beforeClass ( foo,bar = "baz" )
  491. * @codeCoverageIgnore ( foo,bar = "baz" )
  492. * @codeCoverageIgnoreStart ( foo,bar = "baz" )
  493. * @codeCoverageIgnoreEnd ( foo,bar = "baz" )
  494. * @covers ( foo,bar = "baz" )
  495. * @coversDefaultClass ( foo,bar = "baz" )
  496. * @coversNothing ( foo,bar = "baz" )
  497. * @dataProvider ( foo,bar = "baz" )
  498. * @depends ( foo,bar = "baz" )
  499. * @expectedException ( foo,bar = "baz" )
  500. * @expectedExceptionCode ( foo,bar = "baz" )
  501. * @expectedExceptionMessage ( foo,bar = "baz" )
  502. * @expectedExceptionMessageRegExp ( foo,bar = "baz" )
  503. * @group ( foo,bar = "baz" )
  504. * @large ( foo,bar = "baz" )
  505. * @medium ( foo,bar = "baz" )
  506. * @preserveGlobalState ( foo,bar = "baz" )
  507. * @requires ( foo,bar = "baz" )
  508. * @runTestsInSeparateProcesses ( foo,bar = "baz" )
  509. * @runInSeparateProcess ( foo,bar = "baz" )
  510. * @small ( foo,bar = "baz" )
  511. * @test ( foo,bar = "baz" )
  512. * @testdox ( foo,bar = "baz" )
  513. * @ticket ( foo,bar = "baz" )
  514. * @uses ( foo,bar = "baz" )
  515. *
  516. * // PHPCheckStyle
  517. * @SuppressWarnings ( foo,bar = "baz" )
  518. *
  519. * // PHPStorm
  520. * @noinspection ( foo,bar = "baz" )
  521. *
  522. * // PEAR
  523. * @package_version ( foo,bar = "baz" )
  524. *
  525. * // PlantUML
  526. * @enduml ( foo,bar = "baz" )
  527. * @startuml ( foo,bar = "baz" )
  528. *
  529. * // other
  530. * @fix ( foo,bar = "baz" )
  531. * @FIXME ( foo,bar = "baz" )
  532. * @fixme ( foo,bar = "baz" )
  533. * @override
  534. */'],
  535. ]);
  536. }
  537. /**
  538. * @param string $expected
  539. * @param string|null $input
  540. *
  541. * @dataProvider getFixAroundCommasOnlyCases
  542. */
  543. public function testFixAroundCommasOnly($expected, $input = null)
  544. {
  545. $this->fixer->configure([
  546. 'around_parentheses' => false,
  547. 'around_argument_assignments' => false,
  548. 'around_array_assignments' => false,
  549. ]);
  550. $this->doTest($expected, $input);
  551. $this->fixer->configure([
  552. 'around_parentheses' => false,
  553. 'around_commas' => true,
  554. 'around_argument_assignments' => false,
  555. 'around_array_assignments' => false,
  556. ]);
  557. $this->doTest($expected, $input);
  558. }
  559. /**
  560. * @return array
  561. */
  562. public function getFixAroundCommasOnlyCases()
  563. {
  564. return $this->createTestCases([
  565. ['
  566. /**
  567. * @Foo
  568. */'],
  569. ['
  570. /**
  571. * @Foo()
  572. */'],
  573. ['
  574. /**
  575. * @Foo ()
  576. */'],
  577. ['
  578. /**
  579. * @Foo( "bar" )
  580. */'],
  581. ['
  582. /**
  583. * Foo.
  584. *
  585. * @author John Doe
  586. *
  587. * @Foo( "bar", "baz")
  588. */', '
  589. /**
  590. * Foo.
  591. *
  592. * @author John Doe
  593. *
  594. * @Foo( "bar" ,"baz")
  595. */'],
  596. [
  597. '/** @Foo( "bar", "baz") */',
  598. '/** @Foo( "bar" ,"baz") */',
  599. ],
  600. ['
  601. /**
  602. * @Foo( "bar", "baz")
  603. */', '
  604. /**
  605. * @Foo( "bar" , "baz")
  606. */'],
  607. ['
  608. /**
  609. * @Foo(
  610. * "bar",
  611. * "baz"
  612. * )
  613. */', '
  614. /**
  615. * @Foo(
  616. * "bar" ,
  617. * "baz"
  618. * )
  619. */'],
  620. ['
  621. /**
  622. * @Foo(
  623. * "bar",
  624. * "baz"
  625. * )
  626. */', '
  627. /**
  628. * @Foo(
  629. * "bar"
  630. * ,
  631. * "baz"
  632. * )
  633. */'],
  634. ['
  635. /**
  636. * @Foo("bar ,", "baz,")
  637. */'],
  638. ['
  639. /**
  640. * @Foo(
  641. * @Bar ( "foo", "bar"),
  642. * @Baz
  643. * )
  644. */', '
  645. /**
  646. * @Foo(
  647. * @Bar ( "foo" ,"bar") ,
  648. * @Baz
  649. * )
  650. */'],
  651. ['
  652. /**
  653. * @Foo({"bar", "baz"})
  654. */', '
  655. /**
  656. * @Foo({"bar" ,"baz"})
  657. */'],
  658. ['
  659. /**
  660. * @Foo(foo="foo", bar="bar")
  661. */', '
  662. /**
  663. * @Foo(foo="foo" ,bar="bar")
  664. */'],
  665. ['
  666. /**
  667. * @Foo(foo="foo" ,bar="bar"
  668. */'],
  669. ['
  670. /**
  671. * Comment , with a comma.
  672. */'],
  673. ['
  674. /**
  675. * Description with a single " character.
  676. *
  677. * @Foo(foo="string "" with inner quote", bar="string "" with inner quote")
  678. *
  679. * @param mixed description with a single " character.
  680. */', '
  681. /**
  682. * Description with a single " character.
  683. *
  684. * @Foo(foo="string "" with inner quote" ,bar="string "" with inner quote")
  685. *
  686. * @param mixed description with a single " character.
  687. */'],
  688. ['
  689. /**
  690. * // PHPDocumentor 1
  691. * @abstract ( foo,bar = "baz" )
  692. * @access ( foo,bar = "baz" )
  693. * @code ( foo,bar = "baz" )
  694. * @deprec ( foo,bar = "baz" )
  695. * @encode ( foo,bar = "baz" )
  696. * @exception ( foo,bar = "baz" )
  697. * @final ( foo,bar = "baz" )
  698. * @ingroup ( foo,bar = "baz" )
  699. * @inheritdoc ( foo,bar = "baz" )
  700. * @inheritDoc ( foo,bar = "baz" )
  701. * @magic ( foo,bar = "baz" )
  702. * @name ( foo,bar = "baz" )
  703. * @toc ( foo,bar = "baz" )
  704. * @tutorial ( foo,bar = "baz" )
  705. * @private ( foo,bar = "baz" )
  706. * @static ( foo,bar = "baz" )
  707. * @staticvar ( foo,bar = "baz" )
  708. * @staticVar ( foo,bar = "baz" )
  709. * @throw ( foo,bar = "baz" )
  710. *
  711. * // PHPDocumentor 2
  712. * @api ( foo,bar = "baz" )
  713. * @author ( foo,bar = "baz" )
  714. * @category ( foo,bar = "baz" )
  715. * @copyright ( foo,bar = "baz" )
  716. * @deprecated ( foo,bar = "baz" )
  717. * @example ( foo,bar = "baz" )
  718. * @filesource ( foo,bar = "baz" )
  719. * @global ( foo,bar = "baz" )
  720. * @ignore ( foo,bar = "baz" )
  721. * @internal ( foo,bar = "baz" )
  722. * @license ( foo,bar = "baz" )
  723. * @link ( foo,bar = "baz" )
  724. * @method ( foo,bar = "baz" )
  725. * @package ( foo,bar = "baz" )
  726. * @param ( foo,bar = "baz" )
  727. * @property ( foo,bar = "baz" )
  728. * @property-read ( foo,bar = "baz" )
  729. * @property-write ( foo,bar = "baz" )
  730. * @return ( foo,bar = "baz" )
  731. * @see ( foo,bar = "baz" )
  732. * @since ( foo,bar = "baz" )
  733. * @source ( foo,bar = "baz" )
  734. * @subpackage ( foo,bar = "baz" )
  735. * @throws ( foo,bar = "baz" )
  736. * @todo ( foo,bar = "baz" )
  737. * @TODO ( foo,bar = "baz" )
  738. * @usedBy ( foo,bar = "baz" )
  739. * @uses ( foo,bar = "baz" )
  740. * @var ( foo,bar = "baz" )
  741. * @version ( foo,bar = "baz" )
  742. *
  743. * // PHPUnit
  744. * @after ( foo,bar = "baz" )
  745. * @afterClass ( foo,bar = "baz" )
  746. * @backupGlobals ( foo,bar = "baz" )
  747. * @backupStaticAttributes ( foo,bar = "baz" )
  748. * @before ( foo,bar = "baz" )
  749. * @beforeClass ( foo,bar = "baz" )
  750. * @codeCoverageIgnore ( foo,bar = "baz" )
  751. * @codeCoverageIgnoreStart ( foo,bar = "baz" )
  752. * @codeCoverageIgnoreEnd ( foo,bar = "baz" )
  753. * @covers ( foo,bar = "baz" )
  754. * @coversDefaultClass ( foo,bar = "baz" )
  755. * @coversNothing ( foo,bar = "baz" )
  756. * @dataProvider ( foo,bar = "baz" )
  757. * @depends ( foo,bar = "baz" )
  758. * @expectedException ( foo,bar = "baz" )
  759. * @expectedExceptionCode ( foo,bar = "baz" )
  760. * @expectedExceptionMessage ( foo,bar = "baz" )
  761. * @expectedExceptionMessageRegExp ( foo,bar = "baz" )
  762. * @group ( foo,bar = "baz" )
  763. * @large ( foo,bar = "baz" )
  764. * @medium ( foo,bar = "baz" )
  765. * @preserveGlobalState ( foo,bar = "baz" )
  766. * @requires ( foo,bar = "baz" )
  767. * @runTestsInSeparateProcesses ( foo,bar = "baz" )
  768. * @runInSeparateProcess ( foo,bar = "baz" )
  769. * @small ( foo,bar = "baz" )
  770. * @test ( foo,bar = "baz" )
  771. * @testdox ( foo,bar = "baz" )
  772. * @ticket ( foo,bar = "baz" )
  773. * @uses ( foo,bar = "baz" )
  774. *
  775. * // PHPCheckStyle
  776. * @SuppressWarnings ( foo,bar = "baz" )
  777. *
  778. * // PHPStorm
  779. * @noinspection ( foo,bar = "baz" )
  780. *
  781. * // PEAR
  782. * @package_version ( foo,bar = "baz" )
  783. *
  784. * // PlantUML
  785. * @enduml ( foo,bar = "baz" )
  786. * @startuml ( foo,bar = "baz" )
  787. *
  788. * // other
  789. * @fix ( foo,bar = "baz" )
  790. * @FIXME ( foo,bar = "baz" )
  791. * @fixme ( foo,bar = "baz" )
  792. * @override
  793. */'],
  794. ]);
  795. }
  796. /**
  797. * @param string $expected
  798. * @param string|null $input
  799. *
  800. * @dataProvider getFixAroundArgumentAssignmentsOnlyCases
  801. */
  802. public function testFixAroundArgumentAssignmentsOnly($expected, $input = null)
  803. {
  804. $this->fixer->configure([
  805. 'around_parentheses' => false,
  806. 'around_commas' => false,
  807. 'around_array_assignments' => false,
  808. ]);
  809. $this->doTest($expected, $input);
  810. $this->fixer->configure([
  811. 'around_parentheses' => false,
  812. 'around_commas' => false,
  813. 'around_argument_assignments' => true,
  814. 'around_array_assignments' => false,
  815. ]);
  816. $this->doTest($expected, $input);
  817. }
  818. /**
  819. * @return array
  820. */
  821. public function getFixAroundArgumentAssignmentsOnlyCases()
  822. {
  823. return $this->createTestCases([
  824. ['
  825. /**
  826. * @Foo (foo="foo", bar="bar")
  827. */'],
  828. ['
  829. /**
  830. * Foo.
  831. *
  832. * @author John Doe
  833. *
  834. * @Foo(foo="foo", bar="bar")
  835. */', '
  836. /**
  837. * Foo.
  838. *
  839. * @author John Doe
  840. *
  841. * @Foo(foo = "foo", bar = "bar")
  842. */'],
  843. ['
  844. /**
  845. * @Foo(
  846. * foo="foo",
  847. * bar="bar"
  848. * )
  849. */', '
  850. /**
  851. * @Foo(
  852. * foo = "foo",
  853. * bar = "bar"
  854. * )
  855. */'],
  856. ['
  857. /**
  858. * @Foo(foo="foo", bar={"foo" : "foo", "bar"="bar"})
  859. */', '
  860. /**
  861. * @Foo(foo = "foo", bar = {"foo" : "foo", "bar"="bar"})
  862. */'],
  863. [
  864. '/** @Foo(foo="foo", bar={"foo" : "foo", "bar"="bar"}) */',
  865. '/** @Foo(foo = "foo", bar = {"foo" : "foo", "bar"="bar"}) */',
  866. ],
  867. ['
  868. /**
  869. * @Foo(
  870. * foo="foo",
  871. * bar={
  872. * "foo":"foo",
  873. * "bar"="bar"
  874. * }
  875. * )
  876. */', '
  877. /**
  878. * @Foo(
  879. * foo = "foo",
  880. * bar = {
  881. * "foo":"foo",
  882. * "bar"="bar"
  883. * }
  884. * )
  885. */'],
  886. ['
  887. /**
  888. * @Foo(
  889. * foo="foo",
  890. * bar={
  891. * "foo"
  892. * :
  893. * "foo",
  894. * "bar"
  895. * =
  896. * "bar"
  897. * }
  898. * )
  899. */', '
  900. /**
  901. * @Foo(
  902. * foo
  903. * =
  904. * "foo",
  905. * bar
  906. * =
  907. * {
  908. * "foo"
  909. * :
  910. * "foo",
  911. * "bar"
  912. * =
  913. * "bar"
  914. * }
  915. * )
  916. */'],
  917. ['
  918. /**
  919. * @Foo(foo="foo", "bar"=@Bar\Baz({"foo":true, "bar"=false}))
  920. */', '
  921. /**
  922. * @Foo(foo = "foo", "bar" = @Bar\Baz({"foo":true, "bar"=false}))
  923. */'],
  924. ['
  925. /**
  926. * Description with a single " character.
  927. *
  928. * @Foo(foo="string "" with inner quote")
  929. *
  930. * @param mixed description with a single " character.
  931. */', '
  932. /**
  933. * Description with a single " character.
  934. *
  935. * @Foo(foo = "string "" with inner quote")
  936. *
  937. * @param mixed description with a single " character.
  938. */'],
  939. ['
  940. /**
  941. * // PHPDocumentor 1
  942. * @abstract ( foo,bar = "baz" )
  943. * @access ( foo,bar = "baz" )
  944. * @code ( foo,bar = "baz" )
  945. * @deprec ( foo,bar = "baz" )
  946. * @encode ( foo,bar = "baz" )
  947. * @exception ( foo,bar = "baz" )
  948. * @final ( foo,bar = "baz" )
  949. * @ingroup ( foo,bar = "baz" )
  950. * @inheritdoc ( foo,bar = "baz" )
  951. * @inheritDoc ( foo,bar = "baz" )
  952. * @magic ( foo,bar = "baz" )
  953. * @name ( foo,bar = "baz" )
  954. * @toc ( foo,bar = "baz" )
  955. * @tutorial ( foo,bar = "baz" )
  956. * @private ( foo,bar = "baz" )
  957. * @static ( foo,bar = "baz" )
  958. * @staticvar ( foo,bar = "baz" )
  959. * @staticVar ( foo,bar = "baz" )
  960. * @throw ( foo,bar = "baz" )
  961. *
  962. * // PHPDocumentor 2
  963. * @api ( foo,bar = "baz" )
  964. * @author ( foo,bar = "baz" )
  965. * @category ( foo,bar = "baz" )
  966. * @copyright ( foo,bar = "baz" )
  967. * @deprecated ( foo,bar = "baz" )
  968. * @example ( foo,bar = "baz" )
  969. * @filesource ( foo,bar = "baz" )
  970. * @global ( foo,bar = "baz" )
  971. * @ignore ( foo,bar = "baz" )
  972. * @internal ( foo,bar = "baz" )
  973. * @license ( foo,bar = "baz" )
  974. * @link ( foo,bar = "baz" )
  975. * @method ( foo,bar = "baz" )
  976. * @package ( foo,bar = "baz" )
  977. * @param ( foo,bar = "baz" )
  978. * @property ( foo,bar = "baz" )
  979. * @property-read ( foo,bar = "baz" )
  980. * @property-write ( foo,bar = "baz" )
  981. * @return ( foo,bar = "baz" )
  982. * @see ( foo,bar = "baz" )
  983. * @since ( foo,bar = "baz" )
  984. * @source ( foo,bar = "baz" )
  985. * @subpackage ( foo,bar = "baz" )
  986. * @throws ( foo,bar = "baz" )
  987. * @todo ( foo,bar = "baz" )
  988. * @TODO ( foo,bar = "baz" )
  989. * @usedBy ( foo,bar = "baz" )
  990. * @uses ( foo,bar = "baz" )
  991. * @var ( foo,bar = "baz" )
  992. * @version ( foo,bar = "baz" )
  993. *
  994. * // PHPUnit
  995. * @after ( foo,bar = "baz" )
  996. * @afterClass ( foo,bar = "baz" )
  997. * @backupGlobals ( foo,bar = "baz" )
  998. * @backupStaticAttributes ( foo,bar = "baz" )
  999. * @before ( foo,bar = "baz" )
  1000. * @beforeClass ( foo,bar = "baz" )
  1001. * @codeCoverageIgnore ( foo,bar = "baz" )
  1002. * @codeCoverageIgnoreStart ( foo,bar = "baz" )
  1003. * @codeCoverageIgnoreEnd ( foo,bar = "baz" )
  1004. * @covers ( foo,bar = "baz" )
  1005. * @coversDefaultClass ( foo,bar = "baz" )
  1006. * @coversNothing ( foo,bar = "baz" )
  1007. * @dataProvider ( foo,bar = "baz" )
  1008. * @depends ( foo,bar = "baz" )
  1009. * @expectedException ( foo,bar = "baz" )
  1010. * @expectedExceptionCode ( foo,bar = "baz" )
  1011. * @expectedExceptionMessage ( foo,bar = "baz" )
  1012. * @expectedExceptionMessageRegExp ( foo,bar = "baz" )
  1013. * @group ( foo,bar = "baz" )
  1014. * @large ( foo,bar = "baz" )
  1015. * @medium ( foo,bar = "baz" )
  1016. * @preserveGlobalState ( foo,bar = "baz" )
  1017. * @requires ( foo,bar = "baz" )
  1018. * @runTestsInSeparateProcesses ( foo,bar = "baz" )
  1019. * @runInSeparateProcess ( foo,bar = "baz" )
  1020. * @small ( foo,bar = "baz" )
  1021. * @test ( foo,bar = "baz" )
  1022. * @testdox ( foo,bar = "baz" )
  1023. * @ticket ( foo,bar = "baz" )
  1024. * @uses ( foo,bar = "baz" )
  1025. *
  1026. * // PHPCheckStyle
  1027. * @SuppressWarnings ( foo,bar = "baz" )
  1028. *
  1029. * // PHPStorm
  1030. * @noinspection ( foo,bar = "baz" )
  1031. *
  1032. * // PEAR
  1033. * @package_version ( foo,bar = "baz" )
  1034. *
  1035. * // PlantUML
  1036. * @enduml ( foo,bar = "baz" )
  1037. * @startuml ( foo,bar = "baz" )
  1038. *
  1039. * // other
  1040. * @fix ( foo,bar = "baz" )
  1041. * @FIXME ( foo,bar = "baz" )
  1042. * @fixme ( foo,bar = "baz" )
  1043. * @override
  1044. */'],
  1045. ]);
  1046. }
  1047. /**
  1048. * @param string $expected
  1049. * @param string|null $input
  1050. *
  1051. * @dataProvider getFixAroundArrayAssignmentsOnlyCases
  1052. */
  1053. public function testFixAroundArrayAssignmentsOnly($expected, $input = null)
  1054. {
  1055. $this->fixer->configure([
  1056. 'around_parentheses' => false,
  1057. 'around_commas' => false,
  1058. 'around_argument_assignments' => false,
  1059. ]);
  1060. $this->doTest($expected, $input);
  1061. $this->fixer->configure([
  1062. 'around_parentheses' => false,
  1063. 'around_commas' => false,
  1064. 'around_argument_assignments' => false,
  1065. 'around_array_assignments' => true,
  1066. ]);
  1067. $this->doTest($expected, $input);
  1068. }
  1069. /**
  1070. * @return array
  1071. */
  1072. public function getFixAroundArrayAssignmentsOnlyCases()
  1073. {
  1074. return $this->createTestCases([
  1075. ['
  1076. /**
  1077. * @Foo (foo="foo", bar="bar")
  1078. */'],
  1079. ['
  1080. /**
  1081. * Foo.
  1082. *
  1083. * @author John Doe
  1084. *
  1085. * @Foo(foo = "foo", bar = "bar")
  1086. */'],
  1087. ['
  1088. /**
  1089. * @Foo(
  1090. * foo = "foo",
  1091. * bar = "bar"
  1092. * )
  1093. */'],
  1094. ['
  1095. /**
  1096. * @Foo(foo = "foo", bar = {"foo" : "foo", "bar" = "bar"})
  1097. */', '
  1098. /**
  1099. * @Foo(foo = "foo", bar = {"foo" : "foo", "bar"="bar"})
  1100. */'],
  1101. [
  1102. '/** @Foo(foo = "foo", bar = {"foo" : "foo", "bar" = "bar"}) */',
  1103. '/** @Foo(foo = "foo", bar = {"foo" : "foo", "bar"="bar"}) */',
  1104. ],
  1105. ['
  1106. /**
  1107. * @Foo(
  1108. * foo = "foo",
  1109. * bar = {
  1110. * "foo" : "foo",
  1111. * "bar" = "bar"
  1112. * }
  1113. * )
  1114. */', '
  1115. /**
  1116. * @Foo(
  1117. * foo = "foo",
  1118. * bar = {
  1119. * "foo":"foo",
  1120. * "bar"="bar"
  1121. * }
  1122. * )
  1123. */'],
  1124. ['
  1125. /**
  1126. * @Foo(
  1127. * foo
  1128. * =
  1129. * "foo",
  1130. * bar
  1131. * =
  1132. * {
  1133. * "foo" : "foo",
  1134. * "bar" = "bar"
  1135. * }
  1136. * )
  1137. */', '
  1138. /**
  1139. * @Foo(
  1140. * foo
  1141. * =
  1142. * "foo",
  1143. * bar
  1144. * =
  1145. * {
  1146. * "foo"
  1147. * :
  1148. * "foo",
  1149. * "bar"
  1150. * =
  1151. * "bar"
  1152. * }
  1153. * )
  1154. */'],
  1155. ['
  1156. /**
  1157. * @Foo(foo = "foo", "bar" = @Bar\Baz({"foo" : true, "bar" = false}))
  1158. */', '
  1159. /**
  1160. * @Foo(foo = "foo", "bar" = @Bar\Baz({"foo":true, "bar"=false}))
  1161. */'],
  1162. ['
  1163. /**
  1164. * Description with a single " character.
  1165. *
  1166. * @Foo(foo = "string "" with inner quote")
  1167. *
  1168. * @param mixed description with a single " character.
  1169. */'],
  1170. ['
  1171. /**
  1172. * // PHPDocumentor 1
  1173. * @abstract ( foo,bar = "baz" )
  1174. * @access ( foo,bar = "baz" )
  1175. * @code ( foo,bar = "baz" )
  1176. * @deprec ( foo,bar = "baz" )
  1177. * @encode ( foo,bar = "baz" )
  1178. * @exception ( foo,bar = "baz" )
  1179. * @final ( foo,bar = "baz" )
  1180. * @ingroup ( foo,bar = "baz" )
  1181. * @inheritdoc ( foo,bar = "baz" )
  1182. * @inheritDoc ( foo,bar = "baz" )
  1183. * @magic ( foo,bar = "baz" )
  1184. * @name ( foo,bar = "baz" )
  1185. * @toc ( foo,bar = "baz" )
  1186. * @tutorial ( foo,bar = "baz" )
  1187. * @private ( foo,bar = "baz" )
  1188. * @static ( foo,bar = "baz" )
  1189. * @staticvar ( foo,bar = "baz" )
  1190. * @staticVar ( foo,bar = "baz" )
  1191. * @throw ( foo,bar = "baz" )
  1192. *
  1193. * // PHPDocumentor 2
  1194. * @api ( foo,bar = "baz" )
  1195. * @author ( foo,bar = "baz" )
  1196. * @category ( foo,bar = "baz" )
  1197. * @copyright ( foo,bar = "baz" )
  1198. * @deprecated ( foo,bar = "baz" )
  1199. * @example ( foo,bar = "baz" )
  1200. * @filesource ( foo,bar = "baz" )
  1201. * @global ( foo,bar = "baz" )
  1202. * @ignore ( foo,bar = "baz" )
  1203. * @internal ( foo,bar = "baz" )
  1204. * @license ( foo,bar = "baz" )
  1205. * @link ( foo,bar = "baz" )
  1206. * @method ( foo,bar = "baz" )
  1207. * @package ( foo,bar = "baz" )
  1208. * @param ( foo,bar = "baz" )
  1209. * @property ( foo,bar = "baz" )
  1210. * @property-read ( foo,bar = "baz" )
  1211. * @property-write ( foo,bar = "baz" )
  1212. * @return ( foo,bar = "baz" )
  1213. * @see ( foo,bar = "baz" )
  1214. * @since ( foo,bar = "baz" )
  1215. * @source ( foo,bar = "baz" )
  1216. * @subpackage ( foo,bar = "baz" )
  1217. * @throws ( foo,bar = "baz" )
  1218. * @todo ( foo,bar = "baz" )
  1219. * @TODO ( foo,bar = "baz" )
  1220. * @usedBy ( foo,bar = "baz" )
  1221. * @uses ( foo,bar = "baz" )
  1222. * @var ( foo,bar = "baz" )
  1223. * @version ( foo,bar = "baz" )
  1224. *
  1225. * // PHPUnit
  1226. * @after ( foo,bar = "baz" )
  1227. * @afterClass ( foo,bar = "baz" )
  1228. * @backupGlobals ( foo,bar = "baz" )
  1229. * @backupStaticAttributes ( foo,bar = "baz" )
  1230. * @before ( foo,bar = "baz" )
  1231. * @beforeClass ( foo,bar = "baz" )
  1232. * @codeCoverageIgnore ( foo,bar = "baz" )
  1233. * @codeCoverageIgnoreStart ( foo,bar = "baz" )
  1234. * @codeCoverageIgnoreEnd ( foo,bar = "baz" )
  1235. * @covers ( foo,bar = "baz" )
  1236. * @coversDefaultClass ( foo,bar = "baz" )
  1237. * @coversNothing ( foo,bar = "baz" )
  1238. * @dataProvider ( foo,bar = "baz" )
  1239. * @depends ( foo,bar = "baz" )
  1240. * @expectedException ( foo,bar = "baz" )
  1241. * @expectedExceptionCode ( foo,bar = "baz" )
  1242. * @expectedExceptionMessage ( foo,bar = "baz" )
  1243. * @expectedExceptionMessageRegExp ( foo,bar = "baz" )
  1244. * @group ( foo,bar = "baz" )
  1245. * @large ( foo,bar = "baz" )
  1246. * @medium ( foo,bar = "baz" )
  1247. * @preserveGlobalState ( foo,bar = "baz" )
  1248. * @requires ( foo,bar = "baz" )
  1249. * @runTestsInSeparateProcesses ( foo,bar = "baz" )
  1250. * @runInSeparateProcess ( foo,bar = "baz" )
  1251. * @small ( foo,bar = "baz" )
  1252. * @test ( foo,bar = "baz" )
  1253. * @testdox ( foo,bar = "baz" )
  1254. * @ticket ( foo,bar = "baz" )
  1255. * @uses ( foo,bar = "baz" )
  1256. *
  1257. * // PHPCheckStyle
  1258. * @SuppressWarnings ( foo,bar = "baz" )
  1259. *
  1260. * // PHPStorm
  1261. * @noinspection ( foo,bar = "baz" )
  1262. *
  1263. * // PEAR
  1264. * @package_version ( foo,bar = "baz" )
  1265. *
  1266. * // PlantUML
  1267. * @enduml ( foo,bar = "baz" )
  1268. * @startuml ( foo,bar = "baz" )
  1269. *
  1270. * // other
  1271. * @fix ( foo,bar = "baz" )
  1272. * @FIXME ( foo,bar = "baz" )
  1273. * @fixme ( foo,bar = "baz" )
  1274. * @override
  1275. */'],
  1276. ]);
  1277. }
  1278. /**
  1279. * @return array
  1280. */
  1281. public function getInvalidConfigurationCases()
  1282. {
  1283. return array_merge(parent::getInvalidConfigurationCases(), [
  1284. [[
  1285. 'around_parentheses' => false,
  1286. 'around_commas' => false,
  1287. 'around_argument_assignments' => false,
  1288. 'around_array_assignments' => false,
  1289. ]],
  1290. ]);
  1291. }
  1292. }