SingleSpaceAfterConstructFixerTest.php 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460
  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\LanguageConstruct;
  13. use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
  14. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  15. /**
  16. * @author Andreas Möller <am@localheinz.com>
  17. *
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\Fixer\LanguageConstruct\SingleSpaceAfterConstructFixer
  21. */
  22. final class SingleSpaceAfterConstructFixerTest extends AbstractFixerTestCase
  23. {
  24. /**
  25. * @dataProvider provideConfigureRejectsInvalidControlStatementCases
  26. *
  27. * @param mixed $construct
  28. */
  29. public function testConfigureRejectsInvalidControlStatement($construct): void
  30. {
  31. $this->expectException(InvalidFixerConfigurationException::class);
  32. $this->fixer->configure([
  33. 'constructs' => [
  34. $construct,
  35. ],
  36. ]);
  37. }
  38. public static function provideConfigureRejectsInvalidControlStatementCases(): iterable
  39. {
  40. yield 'null' => [null];
  41. yield 'false' => [false];
  42. yield 'true' => [true];
  43. yield 'int' => [0];
  44. yield 'float' => [3.14];
  45. yield 'array' => [[]];
  46. yield 'object' => [new \stdClass()];
  47. yield 'unknown' => ['foo'];
  48. }
  49. /**
  50. * @dataProvider provideFixWithAbstractCases
  51. */
  52. public function testFixWithAbstract(string $expected, ?string $input = null): void
  53. {
  54. $this->fixer->configure([
  55. 'constructs' => [
  56. 'abstract',
  57. ],
  58. ]);
  59. $this->doTest($expected, $input);
  60. }
  61. public static function provideFixWithAbstractCases(): iterable
  62. {
  63. yield [
  64. '<?php abstract class Foo {}; if($a){}',
  65. '<?php abstract class Foo {}; if($a){}',
  66. ];
  67. yield [
  68. '<?php abstract class Foo {};',
  69. '<?php abstract
  70. class Foo {};',
  71. ];
  72. yield [
  73. '<?php abstract /* foo */class Foo {};',
  74. '<?php abstract/* foo */class Foo {};',
  75. ];
  76. yield [
  77. '<?php abstract /* foo */class Foo {};',
  78. '<?php abstract /* foo */class Foo {};',
  79. ];
  80. yield [
  81. '<?php
  82. abstract class Foo
  83. {
  84. abstract function bar();
  85. }',
  86. '<?php
  87. abstract class Foo
  88. {
  89. abstract function bar();
  90. }',
  91. ];
  92. yield [
  93. '<?php
  94. abstract class Foo
  95. {
  96. abstract function bar();
  97. }',
  98. '<?php
  99. abstract class Foo
  100. {
  101. abstract
  102. function bar();
  103. }',
  104. ];
  105. yield [
  106. '<?php
  107. abstract class Foo
  108. {
  109. abstract /* foo */function bar();
  110. }',
  111. '<?php
  112. abstract class Foo
  113. {
  114. abstract /* foo */function bar();
  115. }',
  116. ];
  117. yield [
  118. '<?php
  119. abstract class Foo
  120. {
  121. abstract /* foo */function bar();
  122. }',
  123. '<?php
  124. abstract class Foo
  125. {
  126. abstract/* foo */function bar();
  127. }',
  128. ];
  129. }
  130. /**
  131. * @dataProvider provideFixWithBreakCases
  132. */
  133. public function testFixWithBreak(string $expected, ?string $input = null): void
  134. {
  135. $this->fixer->configure([
  136. 'constructs' => [
  137. 'break',
  138. ],
  139. ]);
  140. $this->doTest($expected, $input);
  141. }
  142. public static function provideFixWithBreakCases(): iterable
  143. {
  144. yield [
  145. '<?php while (true) { break; }',
  146. ];
  147. yield [
  148. '<?php while (true) { break /* foo */; }',
  149. '<?php while (true) { break/* foo */; }',
  150. ];
  151. yield [
  152. '<?php while (true) { break /* foo */; }',
  153. '<?php while (true) { break /* foo */; }',
  154. ];
  155. yield [
  156. '<?php while (true) { break 1; }',
  157. '<?php while (true) { break 1; }',
  158. ];
  159. yield [
  160. '<?php while (true) { break 1; }',
  161. '<?php while (true) { break
  162. 1; }',
  163. ];
  164. yield [
  165. '<?php while (true) { break /* foo */1; }',
  166. '<?php while (true) { break/* foo */1; }',
  167. ];
  168. yield [
  169. '<?php while (true) { break /* foo */1; }',
  170. '<?php while (true) { break /* foo */1; }',
  171. ];
  172. }
  173. /**
  174. * @dataProvider provideFixWithAsCases
  175. */
  176. public function testFixWithAs(string $expected, ?string $input = null): void
  177. {
  178. $this->fixer->configure([
  179. 'constructs' => [
  180. 'as',
  181. ],
  182. ]);
  183. $this->doTest($expected, $input);
  184. }
  185. public static function provideFixWithAsCases(): iterable
  186. {
  187. yield [
  188. '<?php foreach ($foo as $bar) {}',
  189. '<?php foreach ($foo as$bar) {}',
  190. ];
  191. yield [
  192. '<?php foreach ($foo as $bar) {}',
  193. '<?php foreach ($foo as $bar) {}',
  194. ];
  195. yield [
  196. '<?php foreach ($foo as $bar) {}',
  197. '<?php foreach ($foo as
  198. $bar) {}',
  199. ];
  200. yield [
  201. '<?php foreach ($foo as /* foo */$bar) {}',
  202. '<?php foreach ($foo as/* foo */$bar) {}',
  203. ];
  204. yield [
  205. '<?php foreach ($foo as /* foo */$bar) {}',
  206. '<?php foreach ($foo as /* foo */$bar) {}',
  207. ];
  208. yield [
  209. '<?php
  210. class Foo
  211. {
  212. use Bar {
  213. Bar::baz as bar;
  214. }
  215. }',
  216. '<?php
  217. class Foo
  218. {
  219. use Bar {
  220. Bar::baz as bar;
  221. }
  222. }',
  223. ];
  224. yield [
  225. '<?php
  226. class Foo
  227. {
  228. use Bar {
  229. Bar::baz as bar;
  230. }
  231. }',
  232. '<?php
  233. class Foo
  234. {
  235. use Bar {
  236. Bar::baz as
  237. bar;
  238. }
  239. }',
  240. ];
  241. yield [
  242. '<?php
  243. class Foo
  244. {
  245. use Bar {
  246. Bar::baz as /* foo */bar;
  247. }
  248. }',
  249. '<?php
  250. class Foo
  251. {
  252. use Bar {
  253. Bar::baz as/* foo */bar;
  254. }
  255. }',
  256. ];
  257. yield [
  258. '<?php
  259. class Foo
  260. {
  261. use Bar {
  262. Bar::baz as /* foo */bar;
  263. }
  264. }',
  265. '<?php
  266. class Foo
  267. {
  268. use Bar {
  269. Bar::baz as /* foo */bar;
  270. }
  271. }',
  272. ];
  273. }
  274. /**
  275. * @dataProvider provideFixWithCaseCases
  276. */
  277. public function testFixWithCase(string $expected, ?string $input = null): void
  278. {
  279. $this->fixer->configure([
  280. 'constructs' => [
  281. 'case',
  282. ],
  283. ]);
  284. $this->doTest($expected, $input);
  285. }
  286. public static function provideFixWithCaseCases(): iterable
  287. {
  288. yield [
  289. '<?php
  290. switch ($i) {
  291. case $j:
  292. break;
  293. }',
  294. '<?php
  295. switch ($i) {
  296. case$j:
  297. break;
  298. }',
  299. ];
  300. yield [
  301. '<?php
  302. switch ($i) {
  303. case 0:
  304. break;
  305. }',
  306. '<?php
  307. switch ($i) {
  308. case 0:
  309. break;
  310. }',
  311. ];
  312. yield [
  313. '<?php
  314. switch ($i) {
  315. case 0:
  316. break;
  317. }',
  318. '<?php
  319. switch ($i) {
  320. case
  321. 0:
  322. break;
  323. }',
  324. ];
  325. yield [
  326. '<?php
  327. switch ($i) {
  328. case /* foo */0:
  329. break;
  330. }',
  331. '<?php
  332. switch ($i) {
  333. case/* foo */0:
  334. break;
  335. }',
  336. ];
  337. }
  338. /**
  339. * @dataProvider provideFixWithCatchCases
  340. */
  341. public function testFixWithCatch(string $expected, ?string $input = null): void
  342. {
  343. $this->fixer->configure([
  344. 'constructs' => [
  345. 'catch',
  346. ],
  347. ]);
  348. $this->doTest($expected, $input);
  349. }
  350. public static function provideFixWithCatchCases(): iterable
  351. {
  352. yield [
  353. '<?php try {} catch (\Exception $exception) {}',
  354. '<?php try {} catch(\Exception $exception) {}',
  355. ];
  356. yield [
  357. '<?php try {} catch (\Exception $exception) {}',
  358. '<?php try {} catch (\Exception $exception) {}',
  359. ];
  360. yield [
  361. '<?php try {} catch (\Exception $exception) {}',
  362. '<?php try {} catch
  363. (\Exception $exception) {}',
  364. ];
  365. yield [
  366. '<?php try {} catch /* foo */(Exception $exception) {}',
  367. '<?php try {} catch/* foo */(Exception $exception) {}',
  368. ];
  369. yield [
  370. '<?php try {} catch /* foo */(Exception $exception) {}',
  371. '<?php try {} catch /* foo */(Exception $exception) {}',
  372. ];
  373. }
  374. /**
  375. * @dataProvider provideFixWithClassCases
  376. */
  377. public function testFixWithClass(string $expected, ?string $input = null): void
  378. {
  379. $this->fixer->configure([
  380. 'constructs' => [
  381. 'class',
  382. ],
  383. ]);
  384. $this->doTest($expected, $input);
  385. }
  386. public static function provideFixWithClassCases(): iterable
  387. {
  388. yield [
  389. '<?php class Foo {}',
  390. '<?php class Foo {}',
  391. ];
  392. yield [
  393. '<?php class Foo {}',
  394. '<?php class
  395. Foo {}',
  396. ];
  397. yield [
  398. '<?php class /* foo */Foo {}',
  399. '<?php class /* foo */Foo {}',
  400. ];
  401. yield [
  402. '<?php class /* foo */Foo {}',
  403. '<?php class/* foo */Foo {}',
  404. ];
  405. yield [
  406. '<?php $foo = stdClass::class;',
  407. ];
  408. yield [
  409. '<?php $foo = new class {};',
  410. '<?php $foo = new class {};',
  411. ['constructs' => ['class']],
  412. ];
  413. yield [
  414. '<?php $foo = new class {};',
  415. '<?php $foo = new class{};',
  416. ['constructs' => ['class']],
  417. ];
  418. yield [
  419. '<?php $foo = new class /* foo */{};',
  420. '<?php $foo = new class/* foo */{};',
  421. ['constructs' => ['class']],
  422. ];
  423. yield [
  424. '<?php $foo = new class /* foo */{};',
  425. '<?php $foo = new class /* foo */{};',
  426. ['constructs' => ['class']],
  427. ];
  428. yield [
  429. '<?php $foo = new class(){};',
  430. null,
  431. ['constructs' => ['class']],
  432. ];
  433. yield [
  434. '<?php return
  435. $a ? new class(){ public function foo() { echo 1; }}
  436. : 1
  437. ;',
  438. null,
  439. ['constructs' => ['return']],
  440. ];
  441. }
  442. /**
  443. * @dataProvider provideFixWithContinueCases
  444. */
  445. public function testFixWithContinue(string $expected, ?string $input = null): void
  446. {
  447. $this->fixer->configure([
  448. 'constructs' => [
  449. 'continue',
  450. ],
  451. ]);
  452. $this->doTest($expected, $input);
  453. }
  454. public static function provideFixWithContinueCases(): iterable
  455. {
  456. yield [
  457. '<?php while (true) { continue; }',
  458. ];
  459. yield [
  460. '<?php while (true) { continue /* foo */; }',
  461. '<?php while (true) { continue/* foo */; }',
  462. ];
  463. yield [
  464. '<?php while (true) { continue /* foo */; }',
  465. '<?php while (true) { continue /* foo */; }',
  466. ];
  467. yield [
  468. '<?php while (true) { continue 1; }',
  469. '<?php while (true) { continue 1; }',
  470. ];
  471. yield [
  472. '<?php while (true) { continue 1; }',
  473. '<?php while (true) { continue
  474. 1; }',
  475. ];
  476. yield [
  477. '<?php while (true) { continue /* foo*/ 1; }',
  478. '<?php while (true) { continue /* foo*/ 1; }',
  479. ];
  480. }
  481. /**
  482. * @dataProvider provideFixWithConstCases
  483. */
  484. public function testFixWithConst(string $expected, ?string $input = null): void
  485. {
  486. $this->fixer->configure([
  487. 'constructs' => [
  488. 'const',
  489. ],
  490. ]);
  491. $this->doTest($expected, $input);
  492. }
  493. public static function provideFixWithConstCases(): iterable
  494. {
  495. yield [
  496. '<?php class Foo { const FOO = 9000; }',
  497. '<?php class Foo { const FOO = 9000; }',
  498. ];
  499. yield [
  500. '<?php class Foo { const FOO = 9000; }',
  501. '<?php class Foo { const
  502. FOO = 9000; }',
  503. ];
  504. yield [
  505. '<?php class Foo { const /* foo */FOO = 9000; }',
  506. '<?php class Foo { const/* foo */FOO = 9000; }',
  507. ];
  508. yield [
  509. '<?php class Foo { const /* foo */FOO = 9000; }',
  510. '<?php class Foo { const /* foo */FOO = 9000; }',
  511. ];
  512. yield ['<?php class Foo {
  513. const
  514. FOO = 9000,
  515. BAR = 10000;
  516. }',
  517. ];
  518. yield [
  519. '<?php
  520. const
  521. A = 3,
  522. B = 3
  523. ?>',
  524. ];
  525. yield [
  526. '<?php
  527. const A = 3 ?>
  528. <?php
  529. [ ,
  530. ,
  531. ,$z
  532. ] = foo() ;',
  533. '<?php
  534. const A = 3 ?>
  535. <?php
  536. [ ,
  537. ,
  538. ,$z
  539. ] = foo() ;',
  540. ];
  541. yield [
  542. '<?php
  543. const A
  544. =
  545. 1;
  546. ',
  547. '<?php
  548. const
  549. A
  550. =
  551. 1;
  552. ',
  553. ];
  554. }
  555. /**
  556. * @dataProvider provideFixWithConstImportCases
  557. */
  558. public function testFixWithConstImport(string $expected, ?string $input = null): void
  559. {
  560. $this->fixer->configure([
  561. 'constructs' => [
  562. 'const_import',
  563. ],
  564. ]);
  565. $this->doTest($expected, $input);
  566. }
  567. public static function provideFixWithConstImportCases(): iterable
  568. {
  569. yield [
  570. '<?php use const FOO\BAR;',
  571. '<?php use const FOO\BAR;',
  572. ];
  573. yield [
  574. '<?php use const FOO\BAR;',
  575. '<?php use const
  576. FOO\BAR;',
  577. ];
  578. yield [
  579. '<?php use const /* foo */FOO\BAR;',
  580. '<?php use const/* foo */FOO\BAR;',
  581. ];
  582. yield [
  583. '<?php use const /* foo */FOO\BAR;',
  584. '<?php use const /* foo */FOO\BAR;',
  585. ];
  586. }
  587. /**
  588. * @dataProvider provideFixWithCloneCases
  589. */
  590. public function testFixWithClone(string $expected, ?string $input = null): void
  591. {
  592. $this->fixer->configure([
  593. 'constructs' => [
  594. 'clone',
  595. ],
  596. ]);
  597. $this->doTest($expected, $input);
  598. }
  599. public static function provideFixWithCloneCases(): iterable
  600. {
  601. yield [
  602. '<?php clone $foo;',
  603. '<?php clone$foo;',
  604. ];
  605. yield [
  606. '<?php clone $foo;',
  607. '<?php clone $foo;',
  608. ];
  609. yield [
  610. '<?php clone $foo;',
  611. '<?php clone
  612. $foo;',
  613. ];
  614. yield [
  615. '<?php clone /* foo */$foo;',
  616. '<?php clone/* foo */$foo;',
  617. ];
  618. }
  619. /**
  620. * @dataProvider provideFixWithDoCases
  621. */
  622. public function testFixWithDo(string $expected, ?string $input = null): void
  623. {
  624. $this->fixer->configure([
  625. 'constructs' => [
  626. 'do',
  627. ],
  628. ]);
  629. $this->doTest($expected, $input);
  630. }
  631. public static function provideFixWithDoCases(): iterable
  632. {
  633. yield [
  634. '<?php do {} while (true);',
  635. '<?php do{} while (true);',
  636. ];
  637. yield [
  638. '<?php DO {} while (true);',
  639. '<?php DO{} while (true);',
  640. ];
  641. yield [
  642. '<?php do {} while (true);',
  643. '<?php do {} while (true);',
  644. ];
  645. yield [
  646. '<?php do {} while (true);',
  647. '<?php do
  648. {} while (true);',
  649. ];
  650. yield [
  651. '<?php do /* foo*/{} while (true);',
  652. '<?php do/* foo*/{} while (true);',
  653. ];
  654. yield [
  655. '<?php do /* foo*/{} while (true);',
  656. '<?php do /* foo*/{} while (true);',
  657. ];
  658. }
  659. /**
  660. * @dataProvider provideFixWithEchoCases
  661. */
  662. public function testFixWithEcho(string $expected, ?string $input = null): void
  663. {
  664. $this->fixer->configure([
  665. 'constructs' => [
  666. 'echo',
  667. ],
  668. ]);
  669. $this->doTest($expected, $input);
  670. }
  671. public static function provideFixWithEchoCases(): iterable
  672. {
  673. yield [
  674. '<?php echo $foo;',
  675. '<?php echo$foo;',
  676. ];
  677. yield [
  678. '<?php echo 9000;',
  679. '<?php echo 9000;',
  680. ];
  681. yield [
  682. '<?php echo 9000;',
  683. '<?php echo
  684. 9000;',
  685. ];
  686. yield [
  687. '<?php ECHO /* foo */9000;',
  688. '<?php ECHO/* foo */9000;',
  689. ];
  690. }
  691. /**
  692. * @dataProvider provideFixWithElseCases
  693. */
  694. public function testFixWithElse(string $expected, ?string $input = null): void
  695. {
  696. $this->fixer->configure([
  697. 'constructs' => [
  698. 'else',
  699. ],
  700. ]);
  701. $this->doTest($expected, $input);
  702. }
  703. public static function provideFixWithElseCases(): iterable
  704. {
  705. yield [
  706. '<?php if (true) {} else {}',
  707. '<?php if (true) {} else{}',
  708. ];
  709. yield [
  710. '<?php if (true) {} else {}',
  711. '<?php if (true) {} else {}',
  712. ];
  713. yield [
  714. '<?php if (true) {} else {}',
  715. '<?php if (true) {} else
  716. {}',
  717. ];
  718. yield [
  719. '<?php if (true) {} else /* foo */{}',
  720. '<?php if (true) {} else/* foo */{}',
  721. ];
  722. }
  723. /**
  724. * @dataProvider provideFixWithElseIfCases
  725. */
  726. public function testFixWithElseIf(string $expected, ?string $input = null): void
  727. {
  728. $this->fixer->configure([
  729. 'constructs' => [
  730. 'elseif',
  731. ],
  732. ]);
  733. $this->doTest($expected, $input);
  734. }
  735. public static function provideFixWithElseIfCases(): iterable
  736. {
  737. yield [
  738. '<?php if (true) {} elseif (false) {}',
  739. '<?php if (true) {} elseif(false) {}',
  740. ];
  741. yield [
  742. '<?php if (true) {} elseif (false) {}',
  743. '<?php if (true) {} elseif (false) {}',
  744. ];
  745. yield [
  746. '<?php if (true) {} elseif (false) {}',
  747. '<?php if (true) {} elseif
  748. (false) {}',
  749. ];
  750. yield [
  751. '<?php if (true) {} elseif /* foo */(false) {}',
  752. '<?php if (true) {} elseif/* foo */(false) {}',
  753. ];
  754. }
  755. /**
  756. * @dataProvider provideFixWithExtendsCases
  757. */
  758. public function testFixWithExtends(string $expected, ?string $input = null): void
  759. {
  760. $this->fixer->configure([
  761. 'constructs' => [
  762. 'extends',
  763. ],
  764. ]);
  765. $this->doTest($expected, $input);
  766. }
  767. public static function provideFixWithExtendsCases(): iterable
  768. {
  769. yield [
  770. '<?php class Foo extends \InvalidArgumentException {}',
  771. '<?php class Foo extends \InvalidArgumentException {}',
  772. ];
  773. yield [
  774. '<?php class Foo extends \InvalidArgumentException {}',
  775. '<?php class Foo extends
  776. \InvalidArgumentException {}',
  777. ];
  778. yield [
  779. '<?php class Foo extends /* foo */\InvalidArgumentException {}',
  780. '<?php class Foo extends/* foo */\InvalidArgumentException {}',
  781. ];
  782. yield [
  783. '<?php class Foo extends /* foo */\InvalidArgumentException {}',
  784. '<?php class Foo extends /* foo */\InvalidArgumentException {}',
  785. ];
  786. yield [
  787. '<?php interface Foo extends Bar1 {}',
  788. '<?php interface Foo extends Bar1 {}',
  789. ];
  790. yield [
  791. '<?php interface Foo extends Bar2 {}',
  792. '<?php interface Foo extends
  793. Bar2 {}',
  794. ];
  795. yield [
  796. '<?php interface Foo extends /* foo */Bar3 {}',
  797. '<?php interface Foo extends/* foo */Bar3 {}',
  798. ];
  799. yield [
  800. '<?php interface Foo extends /* foo */Bar4 {}',
  801. '<?php interface Foo extends /* foo */Bar4 {}',
  802. ];
  803. yield [
  804. '<?php interface Foo extends Bar5, Baz, Qux {}',
  805. '<?php interface Foo extends Bar5, Baz, Qux {}',
  806. ];
  807. yield [
  808. '<?php interface Foo extends Bar6, Baz, Qux {}',
  809. '<?php interface Foo extends
  810. Bar6, Baz, Qux {}',
  811. ];
  812. yield [
  813. '<?php interface Foo extends /* foo */Bar7, Baz, Qux {}',
  814. '<?php interface Foo extends/* foo */Bar7, Baz, Qux {}',
  815. ];
  816. yield [
  817. '<?php interface Foo extends /* foo */Bar8, Baz, Qux {}',
  818. '<?php interface Foo extends /* foo */Bar8, Baz, Qux {}',
  819. ];
  820. yield [
  821. '<?php interface Foo extends
  822. Bar9,
  823. Baz,
  824. Qux
  825. {}',
  826. ];
  827. yield [
  828. '<?php $foo = new class extends \InvalidArgumentException {};',
  829. '<?php $foo = new class extends \InvalidArgumentException {};',
  830. ];
  831. yield [
  832. '<?php $foo = new class extends \InvalidArgumentException {};',
  833. '<?php $foo = new class extends
  834. \InvalidArgumentException {};',
  835. ];
  836. yield [
  837. '<?php $foo = new class extends /* foo */\InvalidArgumentException {};',
  838. '<?php $foo = new class extends/* foo */\InvalidArgumentException {};',
  839. ];
  840. yield [
  841. '<?php $foo = new class extends /* foo */\InvalidArgumentException {};',
  842. '<?php $foo = new class extends /* foo */\InvalidArgumentException {};',
  843. ];
  844. }
  845. /**
  846. * @dataProvider provideFixWithFinalCases
  847. */
  848. public function testFixWithFinal(string $expected, ?string $input = null): void
  849. {
  850. $this->fixer->configure([
  851. 'constructs' => [
  852. 'final',
  853. ],
  854. ]);
  855. $this->doTest($expected, $input);
  856. }
  857. public static function provideFixWithFinalCases(): iterable
  858. {
  859. yield [
  860. '<?php final class Foo {}',
  861. '<?php final class Foo {}',
  862. ];
  863. yield [
  864. '<?php final class Foo {}',
  865. '<?php final
  866. class Foo {}',
  867. ];
  868. yield [
  869. '<?php final /* foo */class Foo {}',
  870. '<?php final/* foo */class Foo {}',
  871. ];
  872. yield [
  873. '<?php final /* foo */class Foo {}',
  874. '<?php final /* foo */class Foo {}',
  875. ];
  876. yield [
  877. '<?php
  878. class Foo
  879. {
  880. final function bar() {}
  881. }',
  882. '<?php
  883. class Foo
  884. {
  885. final function bar() {}
  886. }',
  887. ];
  888. yield [
  889. '<?php
  890. class Foo
  891. {
  892. final function bar() {}
  893. }',
  894. '<?php
  895. class Foo
  896. {
  897. final
  898. function bar() {}
  899. }',
  900. ];
  901. yield [
  902. '<?php
  903. class Foo
  904. {
  905. final /* foo */function bar() {}
  906. }',
  907. '<?php
  908. class Foo
  909. {
  910. final/* foo */function bar() {}
  911. }',
  912. ];
  913. yield [
  914. '<?php
  915. class Foo
  916. {
  917. final /* foo */function bar() {}
  918. }',
  919. '<?php
  920. class Foo
  921. {
  922. final /* foo */function bar() {}
  923. }',
  924. ];
  925. }
  926. /**
  927. * @dataProvider provideFixWithFinallyCases
  928. */
  929. public function testFixWithFinally(string $expected, ?string $input = null): void
  930. {
  931. $this->fixer->configure([
  932. 'constructs' => [
  933. 'finally',
  934. ],
  935. ]);
  936. $this->doTest($expected, $input);
  937. }
  938. public static function provideFixWithFinallyCases(): iterable
  939. {
  940. yield [
  941. '<?php try {} finally {}',
  942. '<?php try {} finally{}',
  943. ];
  944. yield [
  945. '<?php try {} finally {}',
  946. '<?php try {} finally {}',
  947. ];
  948. yield [
  949. '<?php try {} finally {}',
  950. '<?php try {} finally
  951. {}',
  952. ];
  953. yield [
  954. '<?php try {} finally /* foo */{}',
  955. '<?php try {} finally/* foo */{}',
  956. ];
  957. yield [
  958. '<?php try {} finally /* foo */{}',
  959. '<?php try {} finally /* foo */{}',
  960. ];
  961. }
  962. /**
  963. * @dataProvider provideFixWithForCases
  964. */
  965. public function testFixWithFor(string $expected, ?string $input = null): void
  966. {
  967. $this->fixer->configure([
  968. 'constructs' => [
  969. 'for',
  970. ],
  971. ]);
  972. $this->doTest($expected, $input);
  973. }
  974. public static function provideFixWithForCases(): iterable
  975. {
  976. yield [
  977. '<?php for ($i = 0; $i < 3; ++$i) {}',
  978. '<?php for($i = 0; $i < 3; ++$i) {}',
  979. ];
  980. yield [
  981. '<?php for ($i = 0; $i < 3; ++$i) {}',
  982. '<?php for ($i = 0; $i < 3; ++$i) {}',
  983. ];
  984. yield [
  985. '<?php for ($i = 0; $i < 3; ++$i) {}',
  986. '<?php for
  987. ($i = 0; $i < 3; ++$i) {}',
  988. ];
  989. yield [
  990. '<?php for /* foo */($i = 0; $i < 3; ++$i) {}',
  991. '<?php for/* foo */($i = 0; $i < 3; ++$i) {}',
  992. ];
  993. yield [
  994. '<?php for /* foo */($i = 0; $i < 3; ++$i) {}',
  995. '<?php for /* foo */($i = 0; $i < 3; ++$i) {}',
  996. ];
  997. }
  998. /**
  999. * @dataProvider provideFixWithForeachCases
  1000. */
  1001. public function testFixWithForeach(string $expected, ?string $input = null): void
  1002. {
  1003. $this->fixer->configure([
  1004. 'constructs' => [
  1005. 'foreach',
  1006. ],
  1007. ]);
  1008. $this->doTest($expected, $input);
  1009. }
  1010. public static function provideFixWithForeachCases(): iterable
  1011. {
  1012. yield [
  1013. '<?php foreach ($foo as $bar) {}',
  1014. '<?php foreach($foo as $bar) {}',
  1015. ];
  1016. yield [
  1017. '<?php foreach ($foo as $bar) {}',
  1018. '<?php foreach ($foo as $bar) {}',
  1019. ];
  1020. yield [
  1021. '<?php foreach ($foo as $bar) {}',
  1022. '<?php foreach
  1023. ($foo as $bar) {}',
  1024. ];
  1025. yield [
  1026. '<?php foreach /* foo */($foo as $bar) {}',
  1027. '<?php foreach/* foo */($foo as $bar) {}',
  1028. ];
  1029. yield [
  1030. '<?php foreach /* foo */($foo as $bar) {}',
  1031. '<?php foreach /* foo */($foo as $bar) {}',
  1032. ];
  1033. }
  1034. /**
  1035. * @dataProvider provideFixWithFunctionCases
  1036. */
  1037. public function testFixWithFunction(string $expected, ?string $input = null): void
  1038. {
  1039. $this->fixer->configure([
  1040. 'constructs' => [
  1041. 'function',
  1042. ],
  1043. ]);
  1044. $this->doTest($expected, $input);
  1045. }
  1046. public static function provideFixWithFunctionCases(): iterable
  1047. {
  1048. yield [
  1049. '<?php function foo() {}',
  1050. '<?php function foo() {}',
  1051. ];
  1052. yield [
  1053. '<?php function foo() {}',
  1054. '<?php function
  1055. foo() {}',
  1056. ];
  1057. yield [
  1058. '<?php function /* foo */foo() {}',
  1059. '<?php function/* foo */foo() {}',
  1060. ];
  1061. yield [
  1062. '<?php function /* foo */foo() {}',
  1063. '<?php function /* foo */foo() {}',
  1064. ];
  1065. yield [
  1066. '<?php
  1067. class Foo
  1068. {
  1069. function bar() {}
  1070. }
  1071. ',
  1072. '<?php
  1073. class Foo
  1074. {
  1075. function bar() {}
  1076. }
  1077. ',
  1078. ];
  1079. yield [
  1080. '<?php
  1081. class Foo
  1082. {
  1083. function bar() {}
  1084. }
  1085. ',
  1086. '<?php
  1087. class Foo
  1088. {
  1089. function
  1090. bar() {}
  1091. }
  1092. ',
  1093. ];
  1094. yield [
  1095. '<?php
  1096. class Foo
  1097. {
  1098. function /* foo */bar() {}
  1099. }
  1100. ',
  1101. '<?php
  1102. class Foo
  1103. {
  1104. function/* foo */bar() {}
  1105. }
  1106. ',
  1107. ];
  1108. yield [
  1109. '<?php
  1110. class Foo
  1111. {
  1112. function /* foo */bar() {}
  1113. }
  1114. ',
  1115. '<?php
  1116. class Foo
  1117. {
  1118. function /* foo */bar() {}
  1119. }
  1120. ',
  1121. ];
  1122. }
  1123. /**
  1124. * @dataProvider provideFixWithFunctionImportCases
  1125. */
  1126. public function testFixWithFunctionImport(string $expected, ?string $input = null): void
  1127. {
  1128. $this->fixer->configure([
  1129. 'constructs' => [
  1130. 'function_import',
  1131. ],
  1132. ]);
  1133. $this->doTest($expected, $input);
  1134. }
  1135. public static function provideFixWithFunctionImportCases(): iterable
  1136. {
  1137. yield [
  1138. '<?php use function Foo\bar;',
  1139. '<?php use function Foo\bar;',
  1140. ];
  1141. yield [
  1142. '<?php use function Foo\bar;',
  1143. '<?php use function
  1144. Foo\bar;',
  1145. ];
  1146. yield [
  1147. '<?php use function /* foo */Foo\bar;',
  1148. '<?php use function/* foo */Foo\bar;',
  1149. ];
  1150. yield [
  1151. '<?php use function /* foo */Foo\bar;',
  1152. '<?php use function /* foo */Foo\bar;',
  1153. ];
  1154. }
  1155. /**
  1156. * @dataProvider provideFixWithGlobalCases
  1157. */
  1158. public function testFixWithGlobal(string $expected, ?string $input = null): void
  1159. {
  1160. $this->fixer->configure([
  1161. 'constructs' => [
  1162. 'global',
  1163. ],
  1164. ]);
  1165. $this->doTest($expected, $input);
  1166. }
  1167. public static function provideFixWithGlobalCases(): iterable
  1168. {
  1169. yield [
  1170. '<?php function foo() { global $bar; }',
  1171. '<?php function foo() { global$bar; }',
  1172. ];
  1173. yield [
  1174. '<?php function foo() { global $bar; }',
  1175. '<?php function foo() { global $bar; }',
  1176. ];
  1177. yield [
  1178. '<?php function foo() { global $bar; }',
  1179. '<?php function foo() { global
  1180. $bar; }',
  1181. ];
  1182. yield [
  1183. '<?php function foo() { global /* foo */$bar; }',
  1184. '<?php function foo() { global/* foo */$bar; }',
  1185. ];
  1186. yield [
  1187. '<?php function foo() { global /* foo */$bar; }',
  1188. '<?php function foo() { global /* foo */$bar; }',
  1189. ];
  1190. }
  1191. /**
  1192. * @dataProvider provideFixWithGotoCases
  1193. */
  1194. public function testFixWithGoto(string $expected, ?string $input = null): void
  1195. {
  1196. $this->fixer->configure([
  1197. 'constructs' => [
  1198. 'goto',
  1199. ],
  1200. ]);
  1201. $this->doTest($expected, $input);
  1202. }
  1203. public static function provideFixWithGotoCases(): iterable
  1204. {
  1205. yield [
  1206. '<?php goto foo; foo: echo "Bar";',
  1207. '<?php goto foo; foo: echo "Bar";',
  1208. ];
  1209. yield [
  1210. '<?php goto foo; foo: echo "Bar";',
  1211. '<?php goto
  1212. foo; foo: echo "Bar";',
  1213. ];
  1214. yield [
  1215. '<?php goto /* foo */foo; foo: echo "Bar";',
  1216. '<?php goto/* foo */foo; foo: echo "Bar";',
  1217. ];
  1218. }
  1219. /**
  1220. * @dataProvider provideFixWithIfCases
  1221. */
  1222. public function testFixWithIf(string $expected, ?string $input = null): void
  1223. {
  1224. $this->fixer->configure([
  1225. 'constructs' => [
  1226. 'if',
  1227. ],
  1228. ]);
  1229. $this->doTest($expected, $input);
  1230. }
  1231. public static function provideFixWithIfCases(): iterable
  1232. {
  1233. yield [
  1234. '<?php if ($foo === $bar) {}',
  1235. '<?php if($foo === $bar) {}',
  1236. ];
  1237. yield [
  1238. '<?php if ($foo === $bar) {}',
  1239. '<?php if ($foo === $bar) {}',
  1240. ];
  1241. yield [
  1242. '<?php if ($foo === $bar) {}',
  1243. '<?php if
  1244. ($foo === $bar) {}',
  1245. ];
  1246. yield [
  1247. '<?php if /* foo */($foo === $bar) {}',
  1248. '<?php if/* foo */($foo === $bar) {}',
  1249. ];
  1250. }
  1251. /**
  1252. * @dataProvider provideFixWithImplementsCases
  1253. */
  1254. public function testFixWithImplements(string $expected, ?string $input = null): void
  1255. {
  1256. $this->fixer->configure([
  1257. 'constructs' => [
  1258. 'implements',
  1259. ],
  1260. ]);
  1261. $this->doTest($expected, $input);
  1262. }
  1263. public static function provideFixWithImplementsCases(): iterable
  1264. {
  1265. yield [
  1266. '<?php class Foo implements \Countable {}',
  1267. '<?php class Foo implements \Countable {}',
  1268. ];
  1269. yield [
  1270. '<?php class Foo implements \Countable {}',
  1271. '<?php class Foo implements
  1272. \Countable {}',
  1273. ];
  1274. yield [
  1275. '<?php class Foo implements /* foo */\Countable {}',
  1276. '<?php class Foo implements/* foo */\Countable {}',
  1277. ];
  1278. yield [
  1279. '<?php class Foo implements /* foo */\Countable {}',
  1280. '<?php class Foo implements /* foo */\Countable {}',
  1281. ];
  1282. yield [
  1283. '<?php class Foo implements
  1284. \Countable,
  1285. Bar,
  1286. Baz
  1287. {}',
  1288. ];
  1289. yield [
  1290. '<?php $foo = new class implements \Countable {};',
  1291. '<?php $foo = new class implements \Countable {};',
  1292. ];
  1293. yield [
  1294. '<?php $foo = new class implements \Countable {};',
  1295. '<?php $foo = new class implements
  1296. \Countable {};',
  1297. ];
  1298. yield [
  1299. '<?php $foo = new class implements /* foo */\Countable {};',
  1300. '<?php $foo = new class implements/* foo */\Countable {};',
  1301. ];
  1302. yield [
  1303. '<?php $foo = new class implements /* foo */\Countable {};',
  1304. '<?php $foo = new class implements /* foo */\Countable {};',
  1305. ];
  1306. }
  1307. /**
  1308. * @dataProvider provideFixWithIncludeCases
  1309. */
  1310. public function testFixWithInclude(string $expected, ?string $input = null): void
  1311. {
  1312. $this->fixer->configure([
  1313. 'constructs' => [
  1314. 'include',
  1315. ],
  1316. ]);
  1317. $this->doTest($expected, $input);
  1318. }
  1319. public static function provideFixWithIncludeCases(): iterable
  1320. {
  1321. yield [
  1322. '<?php include "vendor/autoload.php";',
  1323. '<?php include"vendor/autoload.php";',
  1324. ];
  1325. yield [
  1326. '<?php include "vendor/autoload.php";',
  1327. '<?php include "vendor/autoload.php";',
  1328. ];
  1329. yield [
  1330. '<?php include "vendor/autoload.php";',
  1331. '<?php include
  1332. "vendor/autoload.php";',
  1333. ];
  1334. yield [
  1335. '<?php include /* foo */"vendor/autoload.php";',
  1336. '<?php include/* foo */"vendor/autoload.php";',
  1337. ];
  1338. }
  1339. /**
  1340. * @dataProvider provideFixWithIncludeOnceCases
  1341. */
  1342. public function testFixWithIncludeOnce(string $expected, ?string $input = null): void
  1343. {
  1344. $this->fixer->configure([
  1345. 'constructs' => [
  1346. 'include_once',
  1347. ],
  1348. ]);
  1349. $this->doTest($expected, $input);
  1350. }
  1351. public static function provideFixWithIncludeOnceCases(): iterable
  1352. {
  1353. yield [
  1354. '<?php include_once "vendor/autoload.php";',
  1355. '<?php include_once"vendor/autoload.php";',
  1356. ];
  1357. yield [
  1358. '<?php include_once "vendor/autoload.php";',
  1359. '<?php include_once "vendor/autoload.php";',
  1360. ];
  1361. yield [
  1362. '<?php include_once "vendor/autoload.php";',
  1363. '<?php include_once
  1364. "vendor/autoload.php";',
  1365. ];
  1366. yield [
  1367. '<?php include_once /* foo */"vendor/autoload.php";',
  1368. '<?php include_once/* foo */"vendor/autoload.php";',
  1369. ];
  1370. }
  1371. /**
  1372. * @dataProvider provideFixWithInstanceofCases
  1373. */
  1374. public function testFixWithInstanceof(string $expected, ?string $input = null): void
  1375. {
  1376. $this->fixer->configure([
  1377. 'constructs' => [
  1378. 'instanceof',
  1379. ],
  1380. ]);
  1381. $this->doTest($expected, $input);
  1382. }
  1383. public static function provideFixWithInstanceofCases(): iterable
  1384. {
  1385. yield [
  1386. '<?php $foo instanceof \stdClass;',
  1387. '<?php $foo instanceof \stdClass;',
  1388. ];
  1389. yield [
  1390. '<?php $foo instanceof \stdClass;',
  1391. '<?php $foo instanceof
  1392. \stdClass;',
  1393. ];
  1394. yield [
  1395. '<?php $foo instanceof /* foo */\stdClass;',
  1396. '<?php $foo instanceof/* foo */\stdClass;',
  1397. ];
  1398. yield [
  1399. '<?php $foo instanceof /* foo */\stdClass;',
  1400. '<?php $foo instanceof /* foo */\stdClass;',
  1401. ];
  1402. yield [
  1403. '<?php $foo instanceof $bar;',
  1404. '<?php $foo instanceof$bar;',
  1405. ];
  1406. }
  1407. /**
  1408. * @dataProvider provideFixWithInsteadofCases
  1409. */
  1410. public function testFixWithInsteadof(string $expected, ?string $input = null): void
  1411. {
  1412. $this->fixer->configure([
  1413. 'constructs' => [
  1414. 'insteadof',
  1415. ],
  1416. ]);
  1417. $this->doTest($expected, $input);
  1418. }
  1419. public static function provideFixWithInsteadofCases(): iterable
  1420. {
  1421. yield [
  1422. '<?php
  1423. class Talker {
  1424. use A, B {
  1425. B::smallTalk insteadof A;
  1426. A::bigTalk insteadof B;
  1427. }
  1428. }',
  1429. '<?php
  1430. class Talker {
  1431. use A, B {
  1432. B::smallTalk insteadof A;
  1433. A::bigTalk insteadof B;
  1434. }
  1435. }',
  1436. ];
  1437. yield [
  1438. '<?php
  1439. class Talker {
  1440. use A, B {
  1441. B::smallTalk insteadof A;
  1442. A::bigTalk insteadof B;
  1443. }
  1444. }',
  1445. '<?php
  1446. class Talker {
  1447. use A, B {
  1448. B::smallTalk insteadof
  1449. A;
  1450. A::bigTalk insteadof B;
  1451. }
  1452. }',
  1453. ];
  1454. yield [
  1455. '<?php
  1456. class Talker {
  1457. use A, B {
  1458. B::smallTalk insteadof /* foo */A;
  1459. A::bigTalk insteadof B;
  1460. }
  1461. }',
  1462. '<?php
  1463. class Talker {
  1464. use A, B {
  1465. B::smallTalk insteadof/* foo */A;
  1466. A::bigTalk insteadof B;
  1467. }
  1468. }',
  1469. ];
  1470. yield [
  1471. '<?php
  1472. class Talker {
  1473. use A, B {
  1474. B::smallTalk insteadof /* foo */A;
  1475. A::bigTalk insteadof B;
  1476. }
  1477. }',
  1478. '<?php
  1479. class Talker {
  1480. use A, B {
  1481. B::smallTalk insteadof /* foo */A;
  1482. A::bigTalk insteadof B;
  1483. }
  1484. }',
  1485. ];
  1486. }
  1487. /**
  1488. * @dataProvider provideFixWithInterfaceCases
  1489. */
  1490. public function testFixWithInterface(string $expected, ?string $input = null): void
  1491. {
  1492. $this->fixer->configure([
  1493. 'constructs' => [
  1494. 'interface',
  1495. ],
  1496. ]);
  1497. $this->doTest($expected, $input);
  1498. }
  1499. public static function provideFixWithInterfaceCases(): iterable
  1500. {
  1501. yield [
  1502. '<?php interface Foo {}',
  1503. '<?php interface Foo {}',
  1504. ];
  1505. yield [
  1506. '<?php interface Foo {}',
  1507. '<?php interface
  1508. Foo {}',
  1509. ];
  1510. yield [
  1511. '<?php interface /* foo */Foo {}',
  1512. '<?php interface /* foo */Foo {}',
  1513. ];
  1514. yield [
  1515. '<?php interface /* foo */Foo {}',
  1516. '<?php interface/* foo */Foo {}',
  1517. ];
  1518. }
  1519. /**
  1520. * @dataProvider provideFixWithNewCases
  1521. */
  1522. public function testFixWithNew(string $expected, ?string $input = null): void
  1523. {
  1524. $this->fixer->configure([
  1525. 'constructs' => [
  1526. 'new',
  1527. ],
  1528. ]);
  1529. $this->doTest($expected, $input);
  1530. }
  1531. public static function provideFixWithNewCases(): iterable
  1532. {
  1533. yield [
  1534. '<?php new $foo();',
  1535. '<?php new$foo();',
  1536. ];
  1537. yield [
  1538. '<?php new Bar();',
  1539. '<?php new Bar();',
  1540. ];
  1541. yield [
  1542. '<?php new Bar();',
  1543. '<?php new
  1544. Bar();',
  1545. ];
  1546. yield [
  1547. '<?php new /* foo */Bar();',
  1548. '<?php new/* foo */Bar();',
  1549. ];
  1550. }
  1551. /**
  1552. * @dataProvider provideFixWithOpenTagWithEchoCases
  1553. */
  1554. public function testFixWithOpenTagWithEcho(string $expected, ?string $input = null): void
  1555. {
  1556. $this->fixer->configure([
  1557. 'constructs' => [
  1558. 'open_tag_with_echo',
  1559. ],
  1560. ]);
  1561. $this->doTest($expected, $input);
  1562. }
  1563. public static function provideFixWithOpenTagWithEchoCases(): iterable
  1564. {
  1565. yield [
  1566. '<?= $foo ?>',
  1567. '<?=$foo ?>',
  1568. ];
  1569. yield [
  1570. '<?= $foo ?>',
  1571. '<?= $foo ?>',
  1572. ];
  1573. yield [
  1574. '<?= $foo ?>',
  1575. '<?=
  1576. $foo ?>',
  1577. ];
  1578. yield [
  1579. '<?= /* foo */$foo ?>',
  1580. '<?=/* foo */$foo ?>',
  1581. ];
  1582. yield [
  1583. '<?= /* foo */$foo ?>',
  1584. '<?= /* foo */$foo ?>',
  1585. ];
  1586. }
  1587. /**
  1588. * @dataProvider provideFixWithPrintCases
  1589. */
  1590. public function testFixWithPrint(string $expected, ?string $input = null): void
  1591. {
  1592. $this->fixer->configure([
  1593. 'constructs' => [
  1594. 'print',
  1595. ],
  1596. ]);
  1597. $this->doTest($expected, $input);
  1598. }
  1599. public static function provideFixWithPrintCases(): iterable
  1600. {
  1601. yield [
  1602. '<?php print $foo;',
  1603. '<?php print$foo;',
  1604. ];
  1605. yield [
  1606. '<?php print 9000;',
  1607. '<?php print 9000;',
  1608. ];
  1609. yield [
  1610. '<?php print 9000;',
  1611. '<?php print
  1612. 9000;',
  1613. ];
  1614. yield [
  1615. '<?php print /* foo */9000;',
  1616. '<?php print/* foo */9000;',
  1617. ];
  1618. }
  1619. /**
  1620. * @dataProvider provideFixWithPrivateCases
  1621. */
  1622. public function testFixWithPrivate(string $expected, ?string $input = null): void
  1623. {
  1624. $this->fixer->configure([
  1625. 'constructs' => [
  1626. 'private',
  1627. ],
  1628. ]);
  1629. $this->doTest($expected, $input);
  1630. }
  1631. public static function provideFixWithPrivateCases(): iterable
  1632. {
  1633. yield [
  1634. '<?php class Foo { private $bar; }',
  1635. '<?php class Foo { private$bar; }',
  1636. ];
  1637. yield [
  1638. '<?php class Foo { private $bar; }',
  1639. '<?php class Foo { private $bar; }',
  1640. ];
  1641. yield [
  1642. '<?php class Foo { private $bar; }',
  1643. '<?php class Foo { private
  1644. $bar; }',
  1645. ];
  1646. yield [
  1647. '<?php class Foo { private /* foo */$bar; }',
  1648. '<?php class Foo { private/* foo */$bar; }',
  1649. ];
  1650. yield [
  1651. '<?php class Foo { private /* foo */$bar; }',
  1652. '<?php class Foo { private /* foo */$bar; }',
  1653. ];
  1654. yield [
  1655. '<?php class Foo { private function bar() {} }',
  1656. '<?php class Foo { private function bar() {} }',
  1657. ];
  1658. yield [
  1659. '<?php class Foo { private function bar() {} }',
  1660. '<?php class Foo { private
  1661. function bar() {} }',
  1662. ];
  1663. yield [
  1664. '<?php class Foo { private /* foo */function bar() {} }',
  1665. '<?php class Foo { private/* foo */function bar() {} }',
  1666. ];
  1667. yield [
  1668. '<?php class Foo { private /* foo */function bar() {} }',
  1669. '<?php class Foo { private /* foo */function bar() {} }',
  1670. ];
  1671. yield [
  1672. '<?php class Foo { private CONST BAR = 9000; }',
  1673. '<?php class Foo { private CONST BAR = 9000; }',
  1674. ];
  1675. yield [
  1676. '<?php class Foo { private CONST BAR = 9000; }',
  1677. '<?php class Foo { private
  1678. CONST BAR = 9000; }',
  1679. ];
  1680. yield [
  1681. '<?php class Foo { private /* foo */CONST BAR = 9000; }',
  1682. '<?php class Foo { private/* foo */CONST BAR = 9000; }',
  1683. ];
  1684. yield [
  1685. '<?php class Foo { private /* foo */CONST BAR = 9000; }',
  1686. '<?php class Foo { private /* foo */CONST BAR = 9000; }',
  1687. ];
  1688. }
  1689. /**
  1690. * @dataProvider provideFixWithProtectedCases
  1691. */
  1692. public function testFixWithProtected(string $expected, ?string $input = null): void
  1693. {
  1694. $this->fixer->configure([
  1695. 'constructs' => [
  1696. 'protected',
  1697. ],
  1698. ]);
  1699. $this->doTest($expected, $input);
  1700. }
  1701. public static function provideFixWithProtectedCases(): iterable
  1702. {
  1703. yield [
  1704. '<?php class Foo { protected $bar; }',
  1705. '<?php class Foo { protected$bar; }',
  1706. ];
  1707. yield [
  1708. '<?php class Foo { protected $bar; }',
  1709. '<?php class Foo { protected $bar; }',
  1710. ];
  1711. yield [
  1712. '<?php class Foo { protected $bar; }',
  1713. '<?php class Foo { protected
  1714. $bar; }',
  1715. ];
  1716. yield [
  1717. '<?php class Foo { protected /* foo */$bar; }',
  1718. '<?php class Foo { protected/* foo */$bar; }',
  1719. ];
  1720. yield [
  1721. '<?php class Foo { protected /* foo */$bar; }',
  1722. '<?php class Foo { protected /* foo */$bar; }',
  1723. ];
  1724. yield [
  1725. '<?php class Foo { protected function bar() {} }',
  1726. '<?php class Foo { protected function bar() {} }',
  1727. ];
  1728. yield [
  1729. '<?php class Foo { protected function bar() {} }',
  1730. '<?php class Foo { protected
  1731. function bar() {} }',
  1732. ];
  1733. yield [
  1734. '<?php class Foo { protected /* foo */function bar() {} }',
  1735. '<?php class Foo { protected/* foo */function bar() {} }',
  1736. ];
  1737. yield [
  1738. '<?php class Foo { protected /* foo */function bar() {} }',
  1739. '<?php class Foo { protected /* foo */function bar() {} }',
  1740. ];
  1741. yield [
  1742. '<?php class Foo { protected CONST BAR = 9000; }',
  1743. '<?php class Foo { protected CONST BAR = 9000; }',
  1744. ];
  1745. yield [
  1746. '<?php class Foo { protected CONST BAR = 9000; }',
  1747. '<?php class Foo { protected
  1748. CONST BAR = 9000; }',
  1749. ];
  1750. yield [
  1751. '<?php class Foo { protected /* foo */CONST BAR = 9000; }',
  1752. '<?php class Foo { protected/* foo */CONST BAR = 9000; }',
  1753. ];
  1754. yield [
  1755. '<?php class Foo { protected /* foo */CONST BAR = 9000; }',
  1756. '<?php class Foo { protected /* foo */CONST BAR = 9000; }',
  1757. ];
  1758. }
  1759. /**
  1760. * @dataProvider provideFixWithPublicCases
  1761. */
  1762. public function testFixWithPublic(string $expected, ?string $input = null): void
  1763. {
  1764. $this->fixer->configure([
  1765. 'constructs' => [
  1766. 'public',
  1767. ],
  1768. ]);
  1769. $this->doTest($expected, $input);
  1770. }
  1771. public static function provideFixWithPublicCases(): iterable
  1772. {
  1773. yield [
  1774. '<?php class Foo { public $bar; }',
  1775. '<?php class Foo { public$bar; }',
  1776. ];
  1777. yield [
  1778. '<?php class Foo { Public $bar; }',
  1779. '<?php class Foo { Public $bar; }',
  1780. ];
  1781. yield [
  1782. '<?php class Foo { public $bar; }',
  1783. '<?php class Foo { public
  1784. $bar; }',
  1785. ];
  1786. yield [
  1787. '<?php class Foo { public /* foo */$bar; }',
  1788. '<?php class Foo { public/* foo */$bar; }',
  1789. ];
  1790. yield [
  1791. '<?php class Foo { public /* foo */$bar; }',
  1792. '<?php class Foo { public /* foo */$bar; }',
  1793. ];
  1794. yield [
  1795. '<?php class Foo { public function bar() {} }',
  1796. '<?php class Foo { public function bar() {} }',
  1797. ];
  1798. yield [
  1799. '<?php class Foo { public function bar() {} }',
  1800. '<?php class Foo { public
  1801. function bar() {} }',
  1802. ];
  1803. yield [
  1804. '<?php class Foo { public /* foo */function bar() {} }',
  1805. '<?php class Foo { public/* foo */function bar() {} }',
  1806. ];
  1807. yield [
  1808. '<?php class Foo { public /* foo */function bar() {} }',
  1809. '<?php class Foo { public /* foo */function bar() {} }',
  1810. ];
  1811. yield [
  1812. '<?php class Foo { public CONST BAR = 9000; }',
  1813. '<?php class Foo { public CONST BAR = 9000; }',
  1814. ];
  1815. yield [
  1816. '<?php class Foo { public CONST BAR = 9000; }',
  1817. '<?php class Foo { public
  1818. CONST BAR = 9000; }',
  1819. ];
  1820. yield [
  1821. '<?php class Foo { public /* foo */CONST BAR = 9000; }',
  1822. '<?php class Foo { public/* foo */CONST BAR = 9000; }',
  1823. ];
  1824. yield [
  1825. '<?php class Foo { public /* foo */CONST BAR = 9000; }',
  1826. '<?php class Foo { public /* foo */CONST BAR = 9000; }',
  1827. ];
  1828. }
  1829. /**
  1830. * @dataProvider provideFixWithRequireCases
  1831. */
  1832. public function testFixWithRequire(string $expected, ?string $input = null): void
  1833. {
  1834. $this->fixer->configure([
  1835. 'constructs' => [
  1836. 'require',
  1837. ],
  1838. ]);
  1839. $this->doTest($expected, $input);
  1840. }
  1841. public static function provideFixWithRequireCases(): iterable
  1842. {
  1843. yield [
  1844. '<?php require "vendor/autoload.php";',
  1845. '<?php require"vendor/autoload.php";',
  1846. ];
  1847. yield [
  1848. '<?php require "vendor/autoload.php";',
  1849. '<?php require "vendor/autoload.php";',
  1850. ];
  1851. yield [
  1852. '<?php require "vendor/autoload.php";',
  1853. '<?php require
  1854. "vendor/autoload.php";',
  1855. ];
  1856. yield [
  1857. '<?php require /* foo */"vendor/autoload.php";',
  1858. '<?php require/* foo */"vendor/autoload.php";',
  1859. ];
  1860. }
  1861. /**
  1862. * @dataProvider provideFixWithRequireOnceCases
  1863. */
  1864. public function testFixWithRequireOnce(string $expected, ?string $input = null): void
  1865. {
  1866. $this->fixer->configure([
  1867. 'constructs' => [
  1868. 'require_once',
  1869. ],
  1870. ]);
  1871. $this->doTest($expected, $input);
  1872. }
  1873. public static function provideFixWithRequireOnceCases(): iterable
  1874. {
  1875. yield [
  1876. '<?php require_once "vendor/autoload.php";',
  1877. '<?php require_once"vendor/autoload.php";',
  1878. ];
  1879. yield [
  1880. '<?php require_once "vendor/autoload.php";',
  1881. '<?php require_once "vendor/autoload.php";',
  1882. ];
  1883. yield [
  1884. '<?php require_once "vendor/autoload.php";',
  1885. '<?php require_once
  1886. "vendor/autoload.php";',
  1887. ];
  1888. yield [
  1889. '<?php require_once /* foo */"vendor/autoload.php";',
  1890. '<?php require_once/* foo */"vendor/autoload.php";',
  1891. ];
  1892. }
  1893. /**
  1894. * @dataProvider provideFixWithReturnCases
  1895. */
  1896. public function testFixWithReturn(string $expected, ?string $input = null): void
  1897. {
  1898. $this->fixer->configure([
  1899. 'constructs' => [
  1900. 'return',
  1901. ],
  1902. ]);
  1903. $this->doTest($expected, $input);
  1904. }
  1905. public static function provideFixWithReturnCases(): iterable
  1906. {
  1907. yield [
  1908. '<?php return;',
  1909. ];
  1910. yield [
  1911. '<?php return /* foo */;',
  1912. '<?php return/* foo */;',
  1913. ];
  1914. yield [
  1915. '<?php return /* foo */;',
  1916. '<?php return /* foo */;',
  1917. ];
  1918. yield [
  1919. '<?php return $foo;',
  1920. '<?php return$foo;',
  1921. ];
  1922. yield [
  1923. '<?php return 9000;',
  1924. '<?php return 9000;',
  1925. ];
  1926. yield [
  1927. '<?php return 9000;',
  1928. '<?php return
  1929. 9000;',
  1930. ];
  1931. yield [
  1932. '<?php return /* */ 9000 + 1 /* foo */ ?>',
  1933. '<?php return
  1934. /* */ 9000 + 1 /* foo */ ?>',
  1935. ];
  1936. yield [
  1937. '<?php return /* foo */9000;',
  1938. '<?php return/* foo */9000;',
  1939. ];
  1940. yield [
  1941. '<?php return $foo && $bar || $baz;',
  1942. '<?php return
  1943. $foo && $bar || $baz;',
  1944. ];
  1945. yield [
  1946. '<?php
  1947. return
  1948. $foo
  1949. && $bar
  1950. || $baz;',
  1951. ];
  1952. yield [
  1953. '<?php
  1954. return
  1955. $foo &&
  1956. $bar ||
  1957. $baz;',
  1958. ];
  1959. yield [
  1960. '<?php
  1961. return
  1962. $foo
  1963. + $bar
  1964. - $baz;',
  1965. ];
  1966. yield [
  1967. '<?php
  1968. return
  1969. $foo +
  1970. $bar -
  1971. $baz;',
  1972. ];
  1973. yield [
  1974. '<?php
  1975. return
  1976. $foo ?
  1977. $bar :
  1978. $baz;',
  1979. ];
  1980. yield [
  1981. '<?php
  1982. return
  1983. $foo
  1984. ? $bar
  1985. : baz;',
  1986. ];
  1987. yield [
  1988. '<?php
  1989. return
  1990. $foo ?:
  1991. $bar;',
  1992. ];
  1993. yield [
  1994. '<?php
  1995. return
  1996. $foo
  1997. ?: $bar;',
  1998. ];
  1999. yield [
  2000. '<?php
  2001. return
  2002. $foo
  2003. ?: $bar?>',
  2004. ];
  2005. }
  2006. /**
  2007. * @dataProvider provideFixWithStaticCases
  2008. */
  2009. public function testFixWithStatic(string $expected, ?string $input = null): void
  2010. {
  2011. $this->fixer->configure([
  2012. 'constructs' => [
  2013. 'static',
  2014. ],
  2015. ]);
  2016. $this->doTest($expected, $input);
  2017. }
  2018. public static function provideFixWithStaticCases(): iterable
  2019. {
  2020. yield [
  2021. '<?php function foo() { static $bar; }',
  2022. '<?php function foo() { static$bar; }',
  2023. ];
  2024. yield [
  2025. '<?php function foo() { static $bar; }',
  2026. '<?php function foo() { static $bar; }',
  2027. ];
  2028. yield [
  2029. '<?php function foo() { static $bar; }',
  2030. '<?php function foo() { static
  2031. $bar; }',
  2032. ];
  2033. yield [
  2034. '<?php function foo() { static /* foo */$bar; }',
  2035. '<?php function foo() { static/* foo */$bar; }',
  2036. ];
  2037. yield [
  2038. '<?php function foo() { static /* foo */$bar; }',
  2039. '<?php function foo() { static /* foo */$bar; }',
  2040. ];
  2041. yield [
  2042. '<?php class Foo { static function bar() {} }',
  2043. '<?php class Foo { static function bar() {} }',
  2044. ];
  2045. yield [
  2046. '<?php class Foo { static function bar() {} }',
  2047. '<?php class Foo { static
  2048. function bar() {} }',
  2049. ];
  2050. yield [
  2051. '<?php class Foo { static /* foo */function bar() {} }',
  2052. '<?php class Foo { static/* foo */function bar() {} }',
  2053. ];
  2054. yield [
  2055. '<?php class Foo { static /* foo */function bar() {} }',
  2056. '<?php class Foo { static /* foo */function bar() {} }',
  2057. ];
  2058. yield [
  2059. '<?php class Foo { function bar() { return new static(); } }',
  2060. ];
  2061. yield [
  2062. '<?php class Foo { function bar() { return static::class; } }',
  2063. ];
  2064. }
  2065. /**
  2066. * @dataProvider provideFixWithThrowCases
  2067. */
  2068. public function testFixWithThrow(string $expected, ?string $input = null): void
  2069. {
  2070. $this->fixer->configure([
  2071. 'constructs' => [
  2072. 'throw',
  2073. ],
  2074. ]);
  2075. $this->doTest($expected, $input);
  2076. }
  2077. public static function provideFixWithThrowCases(): iterable
  2078. {
  2079. yield [
  2080. '<?php throw $foo;',
  2081. '<?php throw$foo;',
  2082. ];
  2083. yield [
  2084. '<?php throw new Exception();',
  2085. '<?php throw new Exception();',
  2086. ];
  2087. yield [
  2088. '<?php throw new Exception();',
  2089. '<?php throw
  2090. new Exception();',
  2091. ];
  2092. yield [
  2093. '<?php throw /* foo */new Exception();',
  2094. '<?php throw/* foo */new Exception();',
  2095. ];
  2096. }
  2097. /**
  2098. * @dataProvider provideFixWithTraitCases
  2099. */
  2100. public function testFixWithTrait(string $expected, ?string $input = null): void
  2101. {
  2102. $this->fixer->configure([
  2103. 'constructs' => [
  2104. 'trait',
  2105. ],
  2106. ]);
  2107. $this->doTest($expected, $input);
  2108. }
  2109. public static function provideFixWithTraitCases(): iterable
  2110. {
  2111. yield [
  2112. '<?php trait Foo {}',
  2113. '<?php trait Foo {}',
  2114. ];
  2115. yield [
  2116. '<?php trait Foo {}',
  2117. '<?php trait
  2118. Foo {}',
  2119. ];
  2120. yield [
  2121. '<?php trait /* foo */Foo {}',
  2122. '<?php trait /* foo */Foo {}',
  2123. ];
  2124. yield [
  2125. '<?php trait /* foo */Foo {}',
  2126. '<?php trait/* foo */Foo {}',
  2127. ];
  2128. }
  2129. /**
  2130. * @dataProvider provideFixWithTryCases
  2131. */
  2132. public function testFixWithTry(string $expected, ?string $input = null): void
  2133. {
  2134. $this->fixer->configure([
  2135. 'constructs' => [
  2136. 'try',
  2137. ],
  2138. ]);
  2139. $this->doTest($expected, $input);
  2140. }
  2141. public static function provideFixWithTryCases(): iterable
  2142. {
  2143. yield [
  2144. '<?php try {} catch (\Exception $exception) {}',
  2145. '<?php try{} catch (\Exception $exception) {}',
  2146. ];
  2147. yield [
  2148. '<?php try {} catch (\Exception $exception) {}',
  2149. '<?php try {} catch (\Exception $exception) {}',
  2150. ];
  2151. yield [
  2152. '<?php try {} catch (\Exception $exception) {}',
  2153. '<?php try
  2154. {} catch (\Exception $exception) {}',
  2155. ];
  2156. yield [
  2157. '<?php try /* foo */{} catch (\Exception $exception) {}',
  2158. '<?php try/* foo */{} catch (\Exception $exception) {}',
  2159. ];
  2160. yield [
  2161. '<?php try /* foo */{} catch (\Exception $exception) {}',
  2162. '<?php try /* foo */{} catch (\Exception $exception) {}',
  2163. ];
  2164. }
  2165. /**
  2166. * @dataProvider provideFixWithUseCases
  2167. */
  2168. public function testFixWithUse(string $expected, ?string $input = null): void
  2169. {
  2170. $this->fixer->configure([
  2171. 'constructs' => [
  2172. 'use',
  2173. ],
  2174. ]);
  2175. $this->doTest($expected, $input);
  2176. }
  2177. public static function provideFixWithUseCases(): iterable
  2178. {
  2179. yield [
  2180. '<?php use Foo\Bar;',
  2181. '<?php use Foo\Bar;',
  2182. ];
  2183. yield [
  2184. '<?php use Foo\Bar;',
  2185. '<?php use
  2186. Foo\Bar;',
  2187. ];
  2188. yield [
  2189. '<?php use /* foo */Foo\Bar;',
  2190. '<?php use/* foo */Foo\Bar;',
  2191. ];
  2192. yield [
  2193. '<?php use /* foo */Foo\Bar;',
  2194. '<?php use /* foo */Foo\Bar;',
  2195. ];
  2196. yield [
  2197. '<?php use const Foo\BAR;',
  2198. '<?php use const Foo\BAR;',
  2199. ];
  2200. yield [
  2201. '<?php use const Foo\BAR;',
  2202. '<?php use
  2203. const Foo\BAR;',
  2204. ];
  2205. yield [
  2206. '<?php use /* foo */const Foo\BAR;',
  2207. '<?php use/* foo */const Foo\BAR;',
  2208. ];
  2209. yield [
  2210. '<?php use /* foo */const Foo\BAR;',
  2211. '<?php use/* foo */const Foo\BAR;',
  2212. ];
  2213. yield [
  2214. '<?php use function Foo\bar;',
  2215. '<?php use function Foo\bar;',
  2216. ];
  2217. yield [
  2218. '<?php use function Foo\bar;',
  2219. '<?php use
  2220. function Foo\bar;',
  2221. ];
  2222. yield [
  2223. '<?php use /* foo */function Foo\bar;',
  2224. '<?php use/* foo */function Foo\bar;',
  2225. ];
  2226. yield [
  2227. '<?php use /* foo */function Foo\bar;',
  2228. '<?php use/* foo */function Foo\bar;',
  2229. ];
  2230. }
  2231. /**
  2232. * @dataProvider provideFixWithUseLambdaCases
  2233. */
  2234. public function testFixWithUseLambda(string $expected, ?string $input = null): void
  2235. {
  2236. $this->fixer->configure([
  2237. 'constructs' => [
  2238. 'use_lambda',
  2239. ],
  2240. ]);
  2241. $this->doTest($expected, $input);
  2242. }
  2243. public static function provideFixWithUseLambdaCases(): iterable
  2244. {
  2245. yield [
  2246. '<?php $foo = function () use ($bar) {};',
  2247. '<?php $foo = function () use($bar) {};',
  2248. ];
  2249. yield [
  2250. '<?php $foo = function () use ($bar) {};',
  2251. '<?php $foo = function () use ($bar) {};',
  2252. ];
  2253. yield [
  2254. '<?php $foo = function () use ($bar) {};',
  2255. '<?php $foo = function () use
  2256. ($bar) {};',
  2257. ];
  2258. yield [
  2259. '<?php $foo = function () use /* foo */($bar) {};',
  2260. '<?php $foo = function () use/* foo */($bar) {};',
  2261. ];
  2262. yield [
  2263. '<?php $foo = function () use /* foo */($bar) {};',
  2264. '<?php $foo = function () use /* foo */($bar) {};',
  2265. ];
  2266. }
  2267. /**
  2268. * @dataProvider provideFixWithUseTraitCases
  2269. */
  2270. public function testFixWithUseTrait(string $expected, ?string $input = null): void
  2271. {
  2272. $this->fixer->configure([
  2273. 'constructs' => [
  2274. 'use_trait',
  2275. ],
  2276. ]);
  2277. $this->doTest($expected, $input);
  2278. }
  2279. public static function provideFixWithUseTraitCases(): iterable
  2280. {
  2281. yield [
  2282. '<?php class Foo { use Bar; }',
  2283. '<?php class Foo { use Bar; }',
  2284. ];
  2285. yield [
  2286. '<?php class Foo { use Bar; }',
  2287. '<?php class Foo { use
  2288. Bar; }',
  2289. ];
  2290. yield [
  2291. '<?php class Foo { use /* foo */Bar; }',
  2292. '<?php class Foo { use/* foo */Bar; }',
  2293. ];
  2294. yield [
  2295. '<?php class Foo { use /* foo */Bar; }',
  2296. '<?php class Foo { use /* foo */Bar; }',
  2297. ];
  2298. }
  2299. /**
  2300. * @dataProvider provideFixWithVarCases
  2301. */
  2302. public function testFixWithVar(string $expected, ?string $input = null): void
  2303. {
  2304. $this->fixer->configure([
  2305. 'constructs' => [
  2306. 'var',
  2307. ],
  2308. ]);
  2309. $this->doTest($expected, $input);
  2310. }
  2311. public static function provideFixWithVarCases(): iterable
  2312. {
  2313. yield [
  2314. '<?php class Foo { var $bar; }',
  2315. '<?php class Foo { var$bar; }',
  2316. ];
  2317. yield [
  2318. '<?php class Foo { var $bar; }',
  2319. '<?php class Foo { var $bar; }',
  2320. ];
  2321. yield [
  2322. '<?php class Foo { var $bar; }',
  2323. '<?php class Foo { var
  2324. $bar; }',
  2325. ];
  2326. yield [
  2327. '<?php class Foo { var /* foo */$bar; }',
  2328. '<?php class Foo { var/* foo */$bar; }',
  2329. ];
  2330. yield [
  2331. '<?php class Foo { var /* foo */$bar; }',
  2332. '<?php class Foo { var /* foo */$bar; }',
  2333. ];
  2334. }
  2335. /**
  2336. * @dataProvider provideFixWithWhileCases
  2337. */
  2338. public function testFixWithWhile(string $expected, ?string $input = null): void
  2339. {
  2340. $this->fixer->configure([
  2341. 'constructs' => [
  2342. 'while',
  2343. ],
  2344. ]);
  2345. $this->doTest($expected, $input);
  2346. }
  2347. public static function provideFixWithWhileCases(): iterable
  2348. {
  2349. yield [
  2350. '<?php do {} while (true);',
  2351. '<?php do {} while(true);',
  2352. ];
  2353. yield [
  2354. '<?php do {} while (true);',
  2355. '<?php do {} while (true);',
  2356. ];
  2357. yield [
  2358. '<?php do {} while (true);',
  2359. '<?php do {} while
  2360. (true);',
  2361. ];
  2362. yield [
  2363. '<?php do {} while /* foo */(true);',
  2364. '<?php do {} while/* foo */(true);',
  2365. ];
  2366. yield [
  2367. '<?php do {} while /* foo */(true);',
  2368. '<?php do {} while /* foo */(true);',
  2369. ];
  2370. }
  2371. /**
  2372. * @dataProvider provideFixWithYieldCases
  2373. */
  2374. public function testFixWithYield(string $expected, ?string $input = null): void
  2375. {
  2376. $this->fixer->configure([
  2377. 'constructs' => [
  2378. 'yield',
  2379. ],
  2380. ]);
  2381. $this->doTest($expected, $input);
  2382. }
  2383. public static function provideFixWithYieldCases(): iterable
  2384. {
  2385. yield [
  2386. '<?php function foo() { yield $foo; }',
  2387. '<?php function foo() { yield$foo; }',
  2388. ];
  2389. yield [
  2390. '<?php function foo() { yield "Foo"; }',
  2391. '<?php function foo() { yield "Foo"; }',
  2392. ];
  2393. yield [
  2394. '<?php function foo() { yield "Foo"; }',
  2395. '<?php function foo() { yield
  2396. "Foo"; }',
  2397. ];
  2398. yield [
  2399. '<?php function foo() { yield /* foo */"Foo"; }',
  2400. '<?php function foo() { yield/* foo */"Foo"; }',
  2401. ];
  2402. }
  2403. /**
  2404. * @dataProvider provideFixWithYieldFromCases
  2405. */
  2406. public function testFixWithYieldFrom(string $expected, ?string $input = null): void
  2407. {
  2408. $this->fixer->configure([
  2409. 'constructs' => [
  2410. 'yield_from',
  2411. ],
  2412. ]);
  2413. $this->doTest($expected, $input);
  2414. }
  2415. public static function provideFixWithYieldFromCases(): iterable
  2416. {
  2417. yield [
  2418. '<?php function foo() { yield from baz(); }',
  2419. '<?php function foo() { yield from baz(); }',
  2420. ];
  2421. yield [
  2422. '<?php function foo() { yield from $foo; }',
  2423. '<?php function foo() { yield from$foo; }',
  2424. ];
  2425. yield [
  2426. '<?php function foo() { yield from baz(); }',
  2427. '<?php function foo() { yield from baz(); }',
  2428. ];
  2429. yield [
  2430. '<?php function foo() { yield from baz(); }',
  2431. '<?php function foo() { yield from baz(); }',
  2432. ];
  2433. yield [
  2434. '<?php function foo() { yIeLd fRoM baz(); }',
  2435. '<?php function foo() { yIeLd fRoM baz(); }',
  2436. ];
  2437. yield [
  2438. '<?php function foo() { yield from baz(); }',
  2439. '<?php function foo() { yield
  2440. from baz(); }',
  2441. ];
  2442. yield [
  2443. '<?php function foo() { yield from baz(); }',
  2444. '<?php function foo() { yield from
  2445. baz(); }',
  2446. ];
  2447. yield [
  2448. '<?php function foo() { yield from baz(); }',
  2449. '<?php function foo() { yield
  2450. from
  2451. baz(); }',
  2452. ];
  2453. yield [
  2454. '<?php function foo() { yield from /* foo */baz(); }',
  2455. '<?php function foo() { yield from/* foo */baz(); }',
  2456. ];
  2457. yield [
  2458. '<?php function foo() { yield from /* foo */baz(); }',
  2459. '<?php function foo() { yield from /* foo */baz(); }',
  2460. ];
  2461. yield [
  2462. '<?php function foo() { yield from /* foo */baz(); }',
  2463. '<?php function foo() { yield from
  2464. /* foo */baz(); }',
  2465. ];
  2466. }
  2467. /**
  2468. * @dataProvider provideFixWithPhpOpenCases
  2469. */
  2470. public function testFixWithPhpOpen(string $expected, ?string $input = null): void
  2471. {
  2472. $this->fixer->configure([
  2473. 'constructs' => [
  2474. 'php_open',
  2475. ],
  2476. ]);
  2477. $this->doTest($expected, $input);
  2478. }
  2479. public static function provideFixWithPhpOpenCases(): iterable
  2480. {
  2481. yield [
  2482. '<?php echo 1;',
  2483. '<?php echo 1;',
  2484. ];
  2485. yield [
  2486. "<?php\necho 1;",
  2487. ];
  2488. yield [
  2489. "<?php\n echo 1;",
  2490. ];
  2491. yield [
  2492. '<?php ',
  2493. ];
  2494. yield [
  2495. "<?php\n",
  2496. ];
  2497. yield [
  2498. "<?php \necho 1;",
  2499. ];
  2500. yield [
  2501. "<?php \n\necho 1;",
  2502. ];
  2503. }
  2504. /**
  2505. * @dataProvider provideCommentsCases
  2506. */
  2507. public function testComments(string $expected, ?string $input = null): void
  2508. {
  2509. $this->fixer->configure([
  2510. 'constructs' => [
  2511. 'comment',
  2512. 'php_doc',
  2513. ],
  2514. ]);
  2515. $this->doTest($expected, $input);
  2516. }
  2517. public static function provideCommentsCases(): iterable
  2518. {
  2519. yield [
  2520. '<?php
  2521. $a /* 1 */ = /**/ 1;
  2522. $a /** 1 */ = /** 2 */ 1;
  2523. $a = 3; # 3
  2524. $a = 4; /** 4 */
  2525. echo 1;
  2526. ',
  2527. '<?php
  2528. $a /* 1 */= /**/1;
  2529. $a /** 1 */= /** 2 */1;
  2530. $a = 3; # 3
  2531. $a = 4; /** 4 */
  2532. echo 1;
  2533. ',
  2534. ];
  2535. yield 'exceptions' => [
  2536. '<?php
  2537. new Dummy(/* a */);
  2538. new Dummy(/** b */);
  2539. foo(/* c */);
  2540. foo($a /* d */, $b);
  2541. $arr = [/* empty */];
  2542. ',
  2543. ];
  2544. yield 'before_destructuring_square_brace_close' => [
  2545. '<?php
  2546. foreach ($fields as [$field/** @var string*/]) {
  2547. }
  2548. ',
  2549. ];
  2550. }
  2551. /**
  2552. * @dataProvider provideWithNamespaceCases
  2553. */
  2554. public function testWithNamespace(string $expected, ?string $input = null): void
  2555. {
  2556. $this->fixer->configure([
  2557. 'constructs' => [
  2558. 'namespace',
  2559. ],
  2560. ]);
  2561. $this->doTest($expected, $input);
  2562. }
  2563. public static function provideWithNamespaceCases(): iterable
  2564. {
  2565. yield 'simple' => [
  2566. '<?php
  2567. namespace Foo;
  2568. namespace Bar;',
  2569. '<?php
  2570. namespace Foo;
  2571. namespace Bar;',
  2572. ];
  2573. yield 'simple with newlines' => [
  2574. '<?php
  2575. namespace Foo;
  2576. namespace Bar;',
  2577. '<?php
  2578. namespace
  2579. Foo;
  2580. namespace
  2581. Bar;',
  2582. ];
  2583. yield 'braces' => [
  2584. '<?php
  2585. namespace Foo {}
  2586. namespace Bar {}',
  2587. '<?php
  2588. namespace Foo {}
  2589. namespace Bar {}',
  2590. ];
  2591. yield 'braces with newlines' => [
  2592. '<?php
  2593. namespace Foo {}
  2594. namespace Bar {}',
  2595. '<?php
  2596. namespace
  2597. Foo {}
  2598. namespace
  2599. Bar {}',
  2600. ];
  2601. yield 'with // comment' => [
  2602. '<?php
  2603. namespace // comment
  2604. Foo;',
  2605. ];
  2606. yield 'with /* comment */' => [
  2607. '<?php
  2608. namespace /* comment */ Foo;',
  2609. '<?php
  2610. namespace/* comment */ Foo;',
  2611. ];
  2612. }
  2613. /**
  2614. * @dataProvider provideFix80Cases
  2615. *
  2616. * @requires PHP 8.0
  2617. */
  2618. public function testFix80(string $expected, string $input): void
  2619. {
  2620. $this->doTest($expected, $input);
  2621. }
  2622. public static function provideFix80Cases(): iterable
  2623. {
  2624. yield 'match 1' => [
  2625. '<?php echo match ($x) {
  2626. 1, 2 => "Same for 1 and 2",
  2627. };',
  2628. '<?php echo match ($x) {
  2629. 1, 2 => "Same for 1 and 2",
  2630. };',
  2631. ];
  2632. yield 'match 2' => [
  2633. '<?php echo match ($x) {
  2634. 1, 2 => "Same for 1 and 2",
  2635. };',
  2636. '<?php echo match($x) {
  2637. 1, 2 => "Same for 1 and 2",
  2638. };',
  2639. ];
  2640. yield 'constructor property promotion' => [
  2641. '<?php
  2642. class Point {
  2643. public function __construct(
  2644. public float $x = 0.0,
  2645. protected float $y = 0.0,
  2646. private float $z = 0.0,
  2647. ) {}
  2648. }
  2649. ',
  2650. "<?php
  2651. class Point {
  2652. public function __construct(
  2653. public float \$x = 0.0,
  2654. protected\tfloat \$y = 0.0,
  2655. private\nfloat \$z = 0.0,
  2656. ) {}
  2657. }
  2658. ",
  2659. ];
  2660. yield 'attribute' => [
  2661. '<?php class Foo {
  2662. #[Required] // foo
  2663. public $bar1;
  2664. #[Required]
  2665. public $bar2;
  2666. }',
  2667. '<?php class Foo {
  2668. #[Required]// foo
  2669. public $bar1;
  2670. #[Required]
  2671. public $bar2;
  2672. }',
  2673. ];
  2674. yield 'named argument' => [
  2675. '<?php $foo(test: 1);',
  2676. '<?php $foo(test: 1);',
  2677. ];
  2678. }
  2679. /**
  2680. * @dataProvider provideFix81Cases
  2681. *
  2682. * @requires PHP 8.1
  2683. */
  2684. public function testFix81(string $expected, string $input): void
  2685. {
  2686. $this->doTest($expected, $input);
  2687. }
  2688. public static function provideFix81Cases(): iterable
  2689. {
  2690. yield 'readonly' => [
  2691. '<?php
  2692. final class Foo
  2693. {
  2694. public readonly string $prop;
  2695. public function __construct(
  2696. public readonly float $x = 0.0,
  2697. ) {}
  2698. }
  2699. ',
  2700. '<?php
  2701. final class Foo
  2702. {
  2703. public readonly string $prop;
  2704. public function __construct(
  2705. public readonly float $x = 0.0,
  2706. ) {}
  2707. }
  2708. ',
  2709. ];
  2710. yield 'enum' => [
  2711. '<?php
  2712. enum Suit {
  2713. case Hearts;
  2714. }
  2715. ',
  2716. '<?php
  2717. enum Suit {
  2718. case Hearts;
  2719. }
  2720. ',
  2721. ];
  2722. yield 'enum full caps' => [
  2723. '<?php
  2724. ENUM Suit {
  2725. case Hearts;
  2726. }
  2727. ',
  2728. '<?php
  2729. ENUM Suit {
  2730. case Hearts;
  2731. }
  2732. ',
  2733. ];
  2734. yield [
  2735. '<?php class Foo
  2736. {
  2737. final public const X = "foo";
  2738. }',
  2739. '<?php class Foo
  2740. {
  2741. final public const X = "foo";
  2742. }',
  2743. ];
  2744. yield [
  2745. '<?php
  2746. class Test {
  2747. public function __construct(
  2748. public $prop = new Foo,
  2749. ) {}
  2750. }
  2751. ',
  2752. '<?php
  2753. class Test {
  2754. public function __construct(
  2755. public $prop = new Foo,
  2756. ) {}
  2757. }
  2758. ',
  2759. ];
  2760. }
  2761. /**
  2762. * @dataProvider provideFixWithSwitchCases
  2763. */
  2764. public function testFixWithSwitch(string $expected, string $input): void
  2765. {
  2766. $this->fixer->configure([
  2767. 'constructs' => [
  2768. 'switch',
  2769. ],
  2770. ]);
  2771. $this->doTest($expected, $input);
  2772. }
  2773. public static function provideFixWithSwitchCases(): iterable
  2774. {
  2775. yield [
  2776. '<?php
  2777. switch ($a){ case 1: echo 123; }
  2778. switch ($b){ case 1: echo 123; }
  2779. ',
  2780. '<?php
  2781. switch($a){ case 1: echo 123; }
  2782. switch ($b){ case 1: echo 123; }
  2783. ',
  2784. ];
  2785. }
  2786. /**
  2787. * @dataProvider provideTypeColonCases
  2788. */
  2789. public function testTypeColon(string $expected, string $input): void
  2790. {
  2791. $this->fixer->configure([
  2792. 'constructs' => [
  2793. 'type_colon',
  2794. ],
  2795. ]);
  2796. $this->doTest($expected, $input);
  2797. }
  2798. public static function provideTypeColonCases(): iterable
  2799. {
  2800. yield [
  2801. '<?php function foo(): array { return []; }',
  2802. "<?php function foo():\narray { return []; }",
  2803. ];
  2804. yield [
  2805. '<?php interface F { public function foo(): array; }',
  2806. "<?php interface F { public function foo():\tarray; }",
  2807. ];
  2808. yield [
  2809. '<?php $a=1; $f = function () use($a): array {};',
  2810. '<?php $a=1; $f = function () use($a):array {};',
  2811. ];
  2812. yield [
  2813. '<?php fn() : array => [];',
  2814. '<?php fn() : array => [];',
  2815. ];
  2816. yield [
  2817. '<?php $a=1; $f = fn (): array => [];',
  2818. '<?php $a=1; $f = fn (): array => [];',
  2819. ];
  2820. }
  2821. /**
  2822. * @dataProvider provideEnumTypeColonCases
  2823. *
  2824. * @requires PHP 8.1
  2825. */
  2826. public function testEnumTypeColon(string $expected, string $input): void
  2827. {
  2828. $this->fixer->configure([
  2829. 'constructs' => [
  2830. 'type_colon',
  2831. ],
  2832. ]);
  2833. $this->doTest($expected, $input);
  2834. }
  2835. public static function provideEnumTypeColonCases(): iterable
  2836. {
  2837. yield [
  2838. '<?php enum Foo: int {}',
  2839. "<?php enum Foo:\nint {}",
  2840. ];
  2841. yield [
  2842. '<?php enum Foo: string {}',
  2843. '<?php enum Foo:string {}',
  2844. ];
  2845. }
  2846. }