AttributeEmptyParenthesesFixerTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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\AttributeNotation;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author HypeMC <hypemc@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\AttributeNotation\AttributeEmptyParenthesesFixer
  20. *
  21. * @requires PHP 8.0
  22. *
  23. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\AttributeNotation\AttributeEmptyParenthesesFixer>
  24. *
  25. * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\AttributeNotation\AttributeEmptyParenthesesFixer
  26. */
  27. final class AttributeEmptyParenthesesFixerTest extends AbstractFixerTestCase
  28. {
  29. /**
  30. * @param _AutogeneratedInputConfiguration $configuration
  31. *
  32. * @dataProvider provideFixCases
  33. */
  34. public function testFix(string $expected, ?string $input = null, array $configuration = []): void
  35. {
  36. $this->fixer->configure($configuration);
  37. $this->doTest($expected, $input);
  38. }
  39. public static function provideFixCases(): iterable
  40. {
  41. yield 'Without parentheses on various declarations' => [
  42. '<?php
  43. namespace Test;
  44. #[\A\B\Foo]
  45. #[\Bar ]
  46. #[Baz]
  47. #[\Bar, Baz]
  48. #[Corge(4, \'baz qux\')]
  49. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  50. #[\A\B\Foo, \Bar , Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  51. #[
  52. \A\B\Foo,
  53. \Bar ,
  54. Baz,
  55. Corge(4, \'baz qux\'),
  56. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  57. ]
  58. class X
  59. {
  60. #[\A\B\Foo]
  61. #[\Bar ]
  62. #[Baz]
  63. #[\Bar, Baz]
  64. #[Corge(4, \'baz qux\')]
  65. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  66. #[\A\B\Foo, \Bar , Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  67. #[
  68. \A\B\Foo,
  69. \Bar ,
  70. Baz,
  71. Corge(4, \'baz qux\'),
  72. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  73. ]
  74. const Y = 1;
  75. #[\A\B\Foo]
  76. #[\Bar ]
  77. #[Baz]
  78. #[\Bar, Baz]
  79. #[Corge(4, \'baz qux\')]
  80. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  81. #[\A\B\Foo, \Bar , Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  82. #[
  83. \A\B\Foo,
  84. \Bar ,
  85. Baz,
  86. Corge(4, \'baz qux\'),
  87. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  88. ]
  89. public $y;
  90. #[\A\B\Foo]
  91. #[\Bar ]
  92. #[Baz]
  93. #[\Bar, Baz]
  94. #[Corge(4, \'baz qux\')]
  95. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  96. #[\A\B\Foo, \Bar , Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  97. #[
  98. \A\B\Foo,
  99. \Bar ,
  100. Baz,
  101. Corge(4, \'baz qux\'),
  102. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  103. ]
  104. public function y() {}
  105. }
  106. #[\A\B\Foo]
  107. #[\Bar ]
  108. #[Baz]
  109. #[\Bar, Baz]
  110. #[Corge(4, \'baz qux\')]
  111. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  112. #[\A\B\Foo, \Bar , Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  113. #[
  114. \A\B\Foo,
  115. \Bar ,
  116. Baz,
  117. Corge(4, \'baz qux\'),
  118. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  119. ]
  120. function f(
  121. #[\A\B\Foo]
  122. #[\Bar ]
  123. #[Baz]
  124. #[\Bar, Baz]
  125. #[Corge(4, \'baz qux\')]
  126. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  127. #[\A\B\Foo, \Bar , Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  128. #[
  129. \A\B\Foo,
  130. \Bar ,
  131. Baz,
  132. Corge(4, \'baz qux\'),
  133. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  134. ]
  135. string $param,
  136. ) {}
  137. $anon = #[\A\B\Foo] #[\Bar ] #[Baz] #[Corge(4, \'baz qux\')] #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')] function () {};
  138. $short = #[\A\B\Foo] #[\Bar ] #[Baz] #[Corge(4, \'baz qux\')] #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')] fn () => null;
  139. ',
  140. '<?php
  141. namespace Test;
  142. #[\A\B\Foo()]
  143. #[\Bar( )]
  144. #[Baz]
  145. #[\Bar(), Baz()]
  146. #[Corge(4, \'baz qux\')]
  147. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  148. #[\A\B\Foo(), \Bar( ), Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  149. #[
  150. \A\B\Foo(),
  151. \Bar( ),
  152. Baz,
  153. Corge(4, \'baz qux\'),
  154. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  155. ]
  156. class X
  157. {
  158. #[\A\B\Foo()]
  159. #[\Bar( )]
  160. #[Baz]
  161. #[\Bar(), Baz()]
  162. #[Corge(4, \'baz qux\')]
  163. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  164. #[\A\B\Foo(), \Bar( ), Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  165. #[
  166. \A\B\Foo(),
  167. \Bar( ),
  168. Baz,
  169. Corge(4, \'baz qux\'),
  170. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  171. ]
  172. const Y = 1;
  173. #[\A\B\Foo()]
  174. #[\Bar( )]
  175. #[Baz]
  176. #[\Bar(), Baz()]
  177. #[Corge(4, \'baz qux\')]
  178. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  179. #[\A\B\Foo(), \Bar( ), Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  180. #[
  181. \A\B\Foo(),
  182. \Bar( ),
  183. Baz,
  184. Corge(4, \'baz qux\'),
  185. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  186. ]
  187. public $y;
  188. #[\A\B\Foo()]
  189. #[\Bar( )]
  190. #[Baz]
  191. #[\Bar(), Baz()]
  192. #[Corge(4, \'baz qux\')]
  193. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  194. #[\A\B\Foo(), \Bar( ), Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  195. #[
  196. \A\B\Foo(),
  197. \Bar( ),
  198. Baz,
  199. Corge(4, \'baz qux\'),
  200. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  201. ]
  202. public function y() {}
  203. }
  204. #[\A\B\Foo()]
  205. #[\Bar( )]
  206. #[Baz]
  207. #[\Bar(), Baz()]
  208. #[Corge(4, \'baz qux\')]
  209. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  210. #[\A\B\Foo(), \Bar( ), Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  211. #[
  212. \A\B\Foo(),
  213. \Bar( ),
  214. Baz,
  215. Corge(4, \'baz qux\'),
  216. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  217. ]
  218. function f(
  219. #[\A\B\Foo()]
  220. #[\Bar( )]
  221. #[Baz]
  222. #[\Bar(), Baz()]
  223. #[Corge(4, \'baz qux\')]
  224. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  225. #[\A\B\Foo(), \Bar( ), Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  226. #[
  227. \A\B\Foo(),
  228. \Bar( ),
  229. Baz,
  230. Corge(4, \'baz qux\'),
  231. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  232. ]
  233. string $param,
  234. ) {}
  235. $anon = #[\A\B\Foo()] #[\Bar( )] #[Baz] #[Corge(4, \'baz qux\')] #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')] function () {};
  236. $short = #[\A\B\Foo()] #[\Bar( )] #[Baz] #[Corge(4, \'baz qux\')] #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')] fn () => null;
  237. ',
  238. ];
  239. yield 'With parentheses on various declarations' => [
  240. '<?php
  241. namespace Test;
  242. #[\A\B\Foo()]
  243. #[\Bar()]
  244. #[Baz()]
  245. #[\Bar(), Baz()]
  246. #[Corge(4, \'baz qux\')]
  247. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  248. #[\A\B\Foo(), \Bar(), Baz(), Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  249. #[
  250. \A\B\Foo(),
  251. \Bar(),
  252. Baz(),
  253. Corge(4, \'baz qux\'),
  254. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  255. ]
  256. class X
  257. {
  258. #[\A\B\Foo()]
  259. #[\Bar()]
  260. #[Baz()]
  261. #[\Bar(), Baz()]
  262. #[Corge(4, \'baz qux\')]
  263. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  264. #[\A\B\Foo(), \Bar(), Baz(), Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  265. #[
  266. \A\B\Foo(),
  267. \Bar(),
  268. Baz(),
  269. Corge(4, \'baz qux\'),
  270. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  271. ]
  272. const Y = 1;
  273. #[\A\B\Foo()]
  274. #[\Bar()]
  275. #[Baz()]
  276. #[\Bar(), Baz()]
  277. #[Corge(4, \'baz qux\')]
  278. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  279. #[\A\B\Foo(), \Bar(), Baz(), Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  280. #[
  281. \A\B\Foo(),
  282. \Bar(),
  283. Baz(),
  284. Corge(4, \'baz qux\'),
  285. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  286. ]
  287. public $y;
  288. #[\A\B\Foo()]
  289. #[\Bar()]
  290. #[Baz()]
  291. #[\Bar(), Baz()]
  292. #[Corge(4, \'baz qux\')]
  293. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  294. #[\A\B\Foo(), \Bar(), Baz(), Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  295. #[
  296. \A\B\Foo(),
  297. \Bar(),
  298. Baz(),
  299. Corge(4, \'baz qux\'),
  300. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  301. ]
  302. public function y() {}
  303. }
  304. #[\A\B\Foo()]
  305. #[\Bar()]
  306. #[Baz()]
  307. #[\Bar(), Baz()]
  308. #[Corge(4, \'baz qux\')]
  309. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  310. #[\A\B\Foo(), \Bar(), Baz(), Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  311. #[
  312. \A\B\Foo(),
  313. \Bar(),
  314. Baz(),
  315. Corge(4, \'baz qux\'),
  316. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  317. ]
  318. function f(
  319. #[\A\B\Foo()]
  320. #[\Bar()]
  321. #[Baz()]
  322. #[\Bar(), Baz()]
  323. #[Corge(4, \'baz qux\')]
  324. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  325. #[\A\B\Foo(), \Bar(), Baz(), Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  326. #[
  327. \A\B\Foo(),
  328. \Bar(),
  329. Baz(),
  330. Corge(4, \'baz qux\'),
  331. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  332. ]
  333. string $param,
  334. ) {}
  335. $anon = #[\A\B\Foo()] #[\Bar()] #[Baz()] #[Corge(4, \'baz qux\')] #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')] function () {};
  336. $short = #[\A\B\Foo()] #[\Bar()] #[Baz()] #[Corge(4, \'baz qux\')] #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')] fn () => null;
  337. ',
  338. '<?php
  339. namespace Test;
  340. #[\A\B\Foo()]
  341. #[\Bar]
  342. #[Baz]
  343. #[\Bar, Baz]
  344. #[Corge(4, \'baz qux\')]
  345. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  346. #[\A\B\Foo(), \Bar, Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  347. #[
  348. \A\B\Foo(),
  349. \Bar,
  350. Baz,
  351. Corge(4, \'baz qux\'),
  352. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  353. ]
  354. class X
  355. {
  356. #[\A\B\Foo()]
  357. #[\Bar]
  358. #[Baz]
  359. #[\Bar, Baz]
  360. #[Corge(4, \'baz qux\')]
  361. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  362. #[\A\B\Foo(), \Bar, Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  363. #[
  364. \A\B\Foo(),
  365. \Bar,
  366. Baz,
  367. Corge(4, \'baz qux\'),
  368. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  369. ]
  370. const Y = 1;
  371. #[\A\B\Foo()]
  372. #[\Bar]
  373. #[Baz]
  374. #[\Bar, Baz]
  375. #[Corge(4, \'baz qux\')]
  376. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  377. #[\A\B\Foo(), \Bar, Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  378. #[
  379. \A\B\Foo(),
  380. \Bar,
  381. Baz,
  382. Corge(4, \'baz qux\'),
  383. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  384. ]
  385. public $y;
  386. #[\A\B\Foo()]
  387. #[\Bar]
  388. #[Baz]
  389. #[\Bar, Baz]
  390. #[Corge(4, \'baz qux\')]
  391. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  392. #[\A\B\Foo(), \Bar, Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  393. #[
  394. \A\B\Foo(),
  395. \Bar,
  396. Baz,
  397. Corge(4, \'baz qux\'),
  398. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  399. ]
  400. public function y() {}
  401. }
  402. #[\A\B\Foo()]
  403. #[\Bar]
  404. #[Baz]
  405. #[\Bar, Baz]
  406. #[Corge(4, \'baz qux\')]
  407. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  408. #[\A\B\Foo(), \Bar, Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  409. #[
  410. \A\B\Foo(),
  411. \Bar,
  412. Baz,
  413. Corge(4, \'baz qux\'),
  414. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  415. ]
  416. function f(
  417. #[\A\B\Foo()]
  418. #[\Bar]
  419. #[Baz]
  420. #[\Bar, Baz]
  421. #[Corge(4, \'baz qux\')]
  422. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  423. #[\A\B\Foo(), \Bar, Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')]
  424. #[
  425. \A\B\Foo(),
  426. \Bar,
  427. Baz,
  428. Corge(4, \'baz qux\'),
  429. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\'),
  430. ]
  431. string $param,
  432. ) {}
  433. $anon = #[\A\B\Foo()] #[\Bar] #[Baz] #[Corge(4, \'baz qux\')] #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')] function () {};
  434. $short = #[\A\B\Foo()] #[\Bar] #[Baz] #[Corge(4, \'baz qux\')] #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\')] fn () => null;
  435. ',
  436. ['use_parentheses' => true],
  437. ];
  438. }
  439. /**
  440. * @param _AutogeneratedInputConfiguration $configuration
  441. *
  442. * @dataProvider provideFix81Cases
  443. *
  444. * @requires PHP 8.1
  445. */
  446. public function testFix81(string $expected, ?string $input = null, array $configuration = []): void
  447. {
  448. $this->fixer->configure($configuration);
  449. $this->doTest($expected, $input);
  450. }
  451. public static function provideFix81Cases(): iterable
  452. {
  453. yield 'Without parentheses' => [
  454. '<?php
  455. namespace Test;
  456. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\', prop4: new P\R())]
  457. #[\A\B\Foo, \Bar , Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\', prop4: new P\R())]
  458. #[
  459. \A\B\Foo,
  460. \Bar ,
  461. Baz,
  462. Corge(4, \'baz qux\'),
  463. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\', prop4: new P\R()),
  464. ]
  465. class X
  466. {}
  467. ',
  468. '<?php
  469. namespace Test;
  470. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\', prop4: new P\R())]
  471. #[\A\B\Foo(), \Bar( ), Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\', prop4: new P\R())]
  472. #[
  473. \A\B\Foo(),
  474. \Bar( ),
  475. Baz,
  476. Corge(4, \'baz qux\'),
  477. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\', prop4: new P\R()),
  478. ]
  479. class X
  480. {}
  481. ',
  482. ];
  483. yield 'With parentheses' => [
  484. '<?php
  485. namespace Test;
  486. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\', prop4: new P\R())]
  487. #[\A\B\Foo(), \Bar(), Baz(), Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\', prop4: new P\R())]
  488. #[
  489. \A\B\Foo(),
  490. \Bar(),
  491. Baz(),
  492. Corge(4, \'baz qux\'),
  493. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\', prop4: new P\R()),
  494. ]
  495. class X
  496. {}
  497. ',
  498. '<?php
  499. namespace Test;
  500. #[A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\', prop4: new P\R())]
  501. #[\A\B\Foo(), \Bar, Baz, Corge(4, \'baz qux\'), A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\', prop4: new P\R())]
  502. #[
  503. \A\B\Foo(),
  504. \Bar,
  505. Baz,
  506. Corge(4, \'baz qux\'),
  507. A\B\Qux(prop1: [1, 2, 4], prop2: true, prop3: \'foo bar\', prop4: new P\R()),
  508. ]
  509. class X
  510. {}
  511. ',
  512. ['use_parentheses' => true],
  513. ];
  514. }
  515. }