SingleSpaceAroundConstructFixerTest.php 83 KB

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