DoctrineAnnotationSpacesFixerTest.php 39 KB

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