SingleSpaceAfterConstructFixerTest.php 76 KB

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