DoctrineAnnotationSpacesFixerTest.php 41 KB

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