SingleClassElementPerStatementFixerTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  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\ClassNotation;
  13. use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
  14. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  15. use PhpCsFixer\WhitespacesFixerConfig;
  16. /**
  17. * @author Javier Spagnoletti <phansys@gmail.com>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Fixer\ClassNotation\SingleClassElementPerStatementFixer
  22. */
  23. final class SingleClassElementPerStatementFixerTest extends AbstractFixerTestCase
  24. {
  25. /**
  26. * @dataProvider provideFixCases
  27. */
  28. public function testFix(string $expected, ?string $input = null): void
  29. {
  30. $this->doTest($expected, $input);
  31. }
  32. public static function provideFixCases(): iterable
  33. {
  34. yield [
  35. '<?php
  36. class Foo
  37. {
  38. private static $bar1 = array(1,2,3);
  39. private static $bar2 = [1,2,3];
  40. private static $baz1 = array(array(1,2), array(3, 4));
  41. private static $baz2 = array(1,2,3);
  42. private static $aaa1 = 1;
  43. private static $aaa2 = array(2, 2);
  44. private static $aaa3 = 3;
  45. }',
  46. '<?php
  47. class Foo
  48. {
  49. private static $bar1 = array(1,2,3), $bar2 = [1,2,3];
  50. private static $baz1 = array(array(1,2), array(3, 4)), $baz2 = array(1,2,3);
  51. private static $aaa1 = 1, $aaa2 = array(2, 2), $aaa3 = 3;
  52. }',
  53. ];
  54. yield [
  55. '<?php
  56. class Foo
  57. {
  58. const A = 1;
  59. const B = 2;
  60. }
  61. echo Foo::A, Foo::B;
  62. ',
  63. '<?php
  64. class Foo
  65. {
  66. const A = 1, B = 2;
  67. }
  68. echo Foo::A, Foo::B;
  69. ',
  70. ];
  71. yield [
  72. <<<'EOT'
  73. <?php
  74. class Foo { protected static $foo = 1; protected static $bar; protected static $baz=2 ; }
  75. EOT
  76. , <<<'EOT'
  77. <?php
  78. class Foo { protected static $foo = 1,$bar,$baz=2 ; }
  79. EOT
  80. ];
  81. yield [
  82. <<<'EOT'
  83. <?php
  84. class Foo {}
  85. class Bar
  86. {
  87. }
  88. EOT
  89. ];
  90. yield [
  91. <<<'EOT'
  92. <?php
  93. class Foo { protected static $foo = 1; protected static $bar; protected static $baz=2 ; }
  94. EOT
  95. , <<<'EOT'
  96. <?php
  97. class Foo { protected static $foo = 1, $bar, $baz=2 ; }
  98. EOT
  99. ];
  100. yield [
  101. <<<'EOT'
  102. <?php
  103. class Foo { const ONE = 1; const TWO = 2; protected static $foo = 1; protected static $bar; protected static $baz=2 ; const THREE = 3; }
  104. EOT
  105. , <<<'EOT'
  106. <?php
  107. class Foo { const ONE = 1, TWO = 2; protected static $foo = 1, $bar, $baz=2 ; const THREE = 3; }
  108. EOT
  109. ];
  110. yield [
  111. <<<'EOT'
  112. <?php
  113. class Foo {
  114. protected static $foo = 1;
  115. protected static $bar;
  116. protected static $baz=2;
  117. }
  118. EOT
  119. , <<<'EOT'
  120. <?php
  121. class Foo {
  122. protected static $foo = 1,
  123. $bar,
  124. $baz=2;
  125. }
  126. EOT
  127. ];
  128. yield [
  129. <<<'EOT'
  130. <?php
  131. class Foo {
  132. /**
  133. * Some great docblock
  134. */
  135. protected static $foo = 1;
  136. protected static $bar;
  137. protected static $baz=2;
  138. }
  139. EOT
  140. , <<<'EOT'
  141. <?php
  142. class Foo {
  143. /**
  144. * Some great docblock
  145. */
  146. protected static $foo = 1,
  147. $bar,
  148. $baz=2;
  149. }
  150. EOT
  151. ];
  152. yield [
  153. <<<'EOT'
  154. <?php
  155. class Foo {
  156. /**
  157. * @int
  158. */
  159. protected static $foo = 1;
  160. protected static $bar;
  161. protected static $baz=2;
  162. // this is an inline comment, not a docblock
  163. private $var = false;
  164. }
  165. EOT
  166. , <<<'EOT'
  167. <?php
  168. class Foo {
  169. /**
  170. * @int
  171. */
  172. protected static $foo = 1,
  173. $bar,
  174. $baz=2;
  175. // this is an inline comment, not a docblock
  176. private $var = false;
  177. }
  178. EOT
  179. ];
  180. yield [
  181. <<<'EOT'
  182. <?php
  183. class Foo {
  184. /**
  185. * @int
  186. */
  187. protected static $foo = 1;
  188. protected static $bar;
  189. protected static $baz=2;
  190. function doSomething()
  191. {
  192. }
  193. }
  194. EOT
  195. , <<<'EOT'
  196. <?php
  197. class Foo {
  198. /**
  199. * @int
  200. */
  201. protected static $foo = 1,
  202. $bar,
  203. $baz=2;
  204. function doSomething()
  205. {
  206. }
  207. }
  208. EOT
  209. ];
  210. yield 'line_breaks_1' => [
  211. <<<'EOT'
  212. <?php
  213. class Foo
  214. {
  215. public $bar = null;
  216. public $initialized = false;
  217. public $configured = false;
  218. public $called = false;
  219. public $arguments = array();
  220. public $baz = null;
  221. public $drop = false;
  222. function doSomething()
  223. {
  224. }
  225. }
  226. EOT
  227. , <<<'EOT'
  228. <?php
  229. class Foo
  230. {
  231. public $bar = null, $initialized = false, $configured = false, $called = false, $arguments = array();
  232. public $baz = null, $drop = false;
  233. function doSomething()
  234. {
  235. }
  236. }
  237. EOT
  238. ];
  239. yield 'line_breaks_2' => [
  240. <<<'EOT'
  241. <?php
  242. class Foo
  243. {
  244. const TWO = '2';
  245. public $bar = null;
  246. public $initialized = false;
  247. function doSomething()
  248. {
  249. }
  250. }
  251. EOT
  252. , <<<'EOT'
  253. <?php
  254. class Foo
  255. {
  256. const TWO = '2';
  257. public $bar = null, $initialized = false;
  258. function doSomething()
  259. {
  260. }
  261. }
  262. EOT
  263. ];
  264. yield 'line_breaks_3' => [
  265. <<<'EOT'
  266. <?php
  267. class Foo
  268. {
  269. const TWO = '2';
  270. public $bar = null;
  271. public $initialized = false;
  272. function doSomething()
  273. {
  274. }
  275. }
  276. EOT
  277. , <<<'EOT'
  278. <?php
  279. class Foo
  280. {
  281. const TWO = '2';
  282. public $bar = null, $initialized = false;
  283. function doSomething()
  284. {
  285. }
  286. }
  287. EOT
  288. ];
  289. yield 'line_breaks_4' => [
  290. <<<'EOT'
  291. <?php
  292. class Foo
  293. {
  294. public $one = 1;
  295. public $bar = null;
  296. public $initialized = false;
  297. public $configured = false;
  298. public $called = false;
  299. public $arguments = array();
  300. function doSomething()
  301. {
  302. }
  303. }
  304. EOT
  305. , <<<'EOT'
  306. <?php
  307. class Foo
  308. {
  309. public $one = 1;
  310. public $bar = null, $initialized = false, $configured = false, $called = false, $arguments = array();
  311. function doSomething()
  312. {
  313. }
  314. }
  315. EOT
  316. ];
  317. yield 'line_breaks_5' => [
  318. <<<'EOT'
  319. <?php
  320. class Foo
  321. {
  322. public $one = 1; public $bar = null; public $initialized = false; public $configured = false; public $called = false; public $arguments = array();
  323. function doSomething()
  324. {
  325. }
  326. }
  327. EOT
  328. , <<<'EOT'
  329. <?php
  330. class Foo
  331. {
  332. public $one = 1; public $bar = null, $initialized = false, $configured = false, $called = false, $arguments = array();
  333. function doSomething()
  334. {
  335. }
  336. }
  337. EOT
  338. ];
  339. yield 'line_breaks_6' => [
  340. <<<'EOT'
  341. <?php
  342. class Foo
  343. {
  344. public $one = 1;public $bar = null;public $initialized = false;public $configured = false;public $called = false;public $arguments = array();
  345. function doSomething()
  346. {
  347. }
  348. }
  349. EOT
  350. , <<<'EOT'
  351. <?php
  352. class Foo
  353. {
  354. public $one = 1;public $bar = null, $initialized = false, $configured = false, $called = false, $arguments = array();
  355. function doSomething()
  356. {
  357. }
  358. }
  359. EOT
  360. ];
  361. yield 'whitespace_1' => [
  362. <<<'EOT'
  363. <?php
  364. class Foo { public $one = 1; public $bar = null; public $initialized = false; public $configured = false; public $called = false; public $arguments = array();
  365. function doSomething()
  366. {
  367. }
  368. }
  369. EOT
  370. , <<<'EOT'
  371. <?php
  372. class Foo { public $one = 1; public $bar = null,$initialized = false,$configured = false,$called = false,$arguments = array();
  373. function doSomething()
  374. {
  375. }
  376. }
  377. EOT
  378. ];
  379. yield 'whitespace_2' => [
  380. <<<'EOT'
  381. <?php
  382. class Foo { public $one = 1; public $bar = null; public $initialized = false; public $configured = false; public $called=false; public $arguments = array();
  383. function doSomething()
  384. {
  385. }
  386. }
  387. EOT
  388. , <<<'EOT'
  389. <?php
  390. class Foo { public $one = 1; public $bar = null,$initialized = false,$configured = false,$called=false,$arguments = array();
  391. function doSomething()
  392. {
  393. }
  394. }
  395. EOT
  396. ];
  397. yield [
  398. <<<'EOT'
  399. <?php
  400. class Foo { protected static $foo = 1; protected static $bar; protected static $baz=1; }
  401. EOT
  402. , <<<'EOT'
  403. <?php
  404. class Foo { protected static $foo = 1, $bar, $baz=1; }
  405. EOT
  406. ];
  407. yield [
  408. <<<'EOT'
  409. <?php
  410. class Foo { protected static $foo = 1; protected static $bar; protected static $baz=1; }
  411. EOT
  412. , <<<'EOT'
  413. <?php
  414. class Foo { protected static $foo = 1, $bar, $baz=1; }
  415. EOT
  416. ];
  417. yield [
  418. <<<'EOT'
  419. <?php
  420. class Foo { protected $foo = 1; protected $bar; protected $baz=2; }
  421. EOT
  422. , <<<'EOT'
  423. <?php
  424. class Foo { protected $foo = 1, $bar, $baz=2; }
  425. EOT
  426. ];
  427. yield [
  428. <<<'EOT'
  429. <?php
  430. class Foo { var $foo = 1; var $bar; var $baz=2; }
  431. EOT
  432. , <<<'EOT'
  433. <?php
  434. class Foo { var $foo = 1, $bar, $baz=2; }
  435. EOT
  436. ];
  437. yield [
  438. <<<'EOT'
  439. <?php
  440. class Foo { var $foo = 1; var $bar; public function doSomething1() {} var $baz=2; }
  441. EOT
  442. , <<<'EOT'
  443. <?php
  444. class Foo { var $foo = 1, $bar; public function doSomething1() {} var $baz=2; }
  445. EOT
  446. ];
  447. yield [
  448. <<<'EOT'
  449. <?php
  450. class Foo { var $foo = 1; var $bar; public function doSomething2() { global $one, $two, $three; } var $baz=2; }
  451. EOT
  452. , <<<'EOT'
  453. <?php
  454. class Foo { var $foo = 1, $bar; public function doSomething2() { global $one, $two, $three; } var $baz=2; }
  455. EOT
  456. ];
  457. yield [
  458. <<<'EOT'
  459. <?php
  460. class Foo { public function doSomething3() {} protected $foo = 1; protected $bar; protected $baz=2; }
  461. EOT
  462. , <<<'EOT'
  463. <?php
  464. class Foo { public function doSomething3() {} protected $foo = 1, $bar, $baz=2; }
  465. EOT
  466. ];
  467. yield [
  468. <<<'EOT'
  469. <?php
  470. class Foo { public function doSomethingElse() {} protected $foo = 1; protected $bar; protected $baz=2; private $acme =array(); }
  471. EOT
  472. , <<<'EOT'
  473. <?php
  474. class Foo { public function doSomethingElse() {} protected $foo = 1, $bar, $baz=2; private $acme =array(); }
  475. EOT
  476. ];
  477. yield [
  478. <<<'EOT'
  479. <?php
  480. class Foo { public function doSomewhere() {} protected $foo = 1; protected $bar; protected $baz=2; private $acme1 =array(); }
  481. EOT
  482. , <<<'EOT'
  483. <?php
  484. class Foo { public function doSomewhere() {} protected $foo = 1, $bar, $baz=2; private $acme1 =array(); }
  485. EOT
  486. ];
  487. yield [
  488. <<<'EOT'
  489. <?php
  490. class Foo { public function doThis() { global $one1, $two2, $three3; } protected $foo = 1; protected $bar; protected $baz=2; private $acme2 =array(); }
  491. EOT
  492. , <<<'EOT'
  493. <?php
  494. class Foo { public function doThis() { global $one1, $two2, $three3; } protected $foo = 1, $bar, $baz=2; private $acme2 =array(); }
  495. EOT
  496. ];
  497. yield [
  498. '<?php
  499. class Foo
  500. {
  501. const A = 1;
  502. const #
  503. B#
  504. =#
  505. 2#
  506. ;#
  507. }
  508. echo Foo::A, Foo::B;
  509. ',
  510. '<?php
  511. class Foo
  512. {
  513. const A = 1,#
  514. B#
  515. =#
  516. 2#
  517. ;#
  518. }
  519. echo Foo::A, Foo::B;
  520. ',
  521. ];
  522. yield [
  523. '<?php
  524. class Token {
  525. const PUBLIC_CONST = 0;
  526. private const PRIVATE_CONST = 0;
  527. protected const PROTECTED_CONST = 0;
  528. public const PUBLIC_CONST_TWO = 0;
  529. public const TEST_71 = 0;
  530. }
  531. ',
  532. '<?php
  533. class Token {
  534. const PUBLIC_CONST = 0;
  535. private const PRIVATE_CONST = 0;
  536. protected const PROTECTED_CONST = 0;
  537. public const PUBLIC_CONST_TWO = 0, TEST_71 = 0;
  538. }
  539. ',
  540. ];
  541. yield [
  542. '<?php class Foo {
  543. private int $foo;
  544. private int $bar;
  545. }',
  546. '<?php class Foo {
  547. private int $foo, $bar;
  548. }',
  549. ];
  550. yield [
  551. '<?php class Foo {
  552. protected ?string $foo;
  553. protected ?string $bar;
  554. }',
  555. '<?php class Foo {
  556. protected ?string $foo, $bar;
  557. }',
  558. ];
  559. yield [
  560. '<?php class Foo {
  561. public ? string $foo;
  562. public ? string $bar;
  563. }',
  564. '<?php class Foo {
  565. public ? string $foo, $bar;
  566. }',
  567. ];
  568. yield [
  569. '<?php class Foo {
  570. var ? Foo\Bar $foo;
  571. var ? Foo\Bar $bar;
  572. }',
  573. '<?php class Foo {
  574. var ? Foo\Bar $foo, $bar;
  575. }',
  576. ];
  577. yield [
  578. '<?php class Foo {
  579. var array $foo;
  580. var array $bar;
  581. }',
  582. '<?php class Foo {
  583. var array $foo, $bar;
  584. }',
  585. ];
  586. }
  587. /**
  588. * @param array<string, mixed> $configuration
  589. *
  590. * @dataProvider provideFixWithConfigurationCases
  591. */
  592. public function testFixWithConfiguration(array $configuration, string $expected): void
  593. {
  594. static $input = <<<'EOT'
  595. <?php
  596. class Foo
  597. {
  598. const SOME_CONST = 'a', OTHER_CONST = 'b';
  599. protected static $foo = 1, $bar = 2;
  600. }
  601. EOT;
  602. $this->fixer->configure(['elements' => $configuration]);
  603. $this->doTest($expected, $input);
  604. }
  605. public static function provideFixWithConfigurationCases(): iterable
  606. {
  607. yield [
  608. ['const', 'property'],
  609. <<<'EOT'
  610. <?php
  611. class Foo
  612. {
  613. const SOME_CONST = 'a';
  614. const OTHER_CONST = 'b';
  615. protected static $foo = 1;
  616. protected static $bar = 2;
  617. }
  618. EOT
  619. ];
  620. yield [
  621. ['const'],
  622. <<<'EOT'
  623. <?php
  624. class Foo
  625. {
  626. const SOME_CONST = 'a';
  627. const OTHER_CONST = 'b';
  628. protected static $foo = 1, $bar = 2;
  629. }
  630. EOT
  631. ];
  632. yield [
  633. ['property'],
  634. <<<'EOT'
  635. <?php
  636. class Foo
  637. {
  638. const SOME_CONST = 'a', OTHER_CONST = 'b';
  639. protected static $foo = 1;
  640. protected static $bar = 2;
  641. }
  642. EOT
  643. ];
  644. }
  645. public function testWrongConfig(): void
  646. {
  647. $this->expectException(InvalidFixerConfigurationException::class);
  648. $this->expectExceptionMessageMatches('/^\[single_class_element_per_statement\] Invalid configuration: The option "elements" .*\.$/');
  649. $this->fixer->configure(['elements' => ['foo']]);
  650. }
  651. /**
  652. * @dataProvider provideMessyWhitespacesCases
  653. */
  654. public function testMessyWhitespaces(string $expected, ?string $input = null): void
  655. {
  656. $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n"));
  657. $this->doTest($expected, $input);
  658. }
  659. public static function provideMessyWhitespacesCases(): iterable
  660. {
  661. yield [
  662. "<?php\r\n\tclass Foo {\r\n\t\tconst AAA=0;\r\n\t\tconst BBB=1;\r\n\t}",
  663. "<?php\r\n\tclass Foo {\r\n\t\tconst AAA=0, BBB=1;\r\n\t}",
  664. ];
  665. }
  666. public function testAnonymousClassFixing(): void
  667. {
  668. $this->doTest(
  669. '<?php
  670. $a = new class() {
  671. const PUBLIC_CONST_TWO = 0;
  672. const TEST_70 = 0;
  673. public function a() {
  674. }
  675. };
  676. class C
  677. {
  678. public function A()
  679. {
  680. $a = new class() {
  681. const PUBLIC_CONST_TWO = 0;
  682. const TEST_70 = 0;
  683. public function a() {}
  684. };
  685. }
  686. }
  687. ',
  688. '<?php
  689. $a = new class() {
  690. const PUBLIC_CONST_TWO = 0, TEST_70 = 0;
  691. public function a() {
  692. }
  693. };
  694. class C
  695. {
  696. public function A()
  697. {
  698. $a = new class() {
  699. const PUBLIC_CONST_TWO = 0, TEST_70 = 0;
  700. public function a() {}
  701. };
  702. }
  703. }
  704. '
  705. );
  706. }
  707. /**
  708. * @dataProvider provideFix80Cases
  709. *
  710. * @requires PHP 8.0
  711. */
  712. public function testFix80(string $expected, string $input): void
  713. {
  714. $this->doTest($expected, $input);
  715. }
  716. public static function provideFix80Cases(): iterable
  717. {
  718. yield [
  719. '<?php
  720. class Foo
  721. {
  722. private string|int $prop1;
  723. private string|int $prop2;
  724. }
  725. ',
  726. '<?php
  727. class Foo
  728. {
  729. private string|int $prop1, $prop2;
  730. }
  731. ',
  732. ];
  733. }
  734. /**
  735. * @dataProvider provideFix81Cases
  736. *
  737. * @requires PHP 8.1
  738. */
  739. public function testFix81(string $expected, ?string $input = null): void
  740. {
  741. $this->doTest($expected, $input);
  742. }
  743. public static function provideFix81Cases(): iterable
  744. {
  745. yield [
  746. '<?php
  747. class Foo
  748. {
  749. readonly int $a;
  750. readonly int $b;
  751. public readonly int $c;
  752. public readonly int $d;
  753. readonly private string /*1*/$e;
  754. readonly private string /*2*/$f;
  755. readonly float $g;
  756. protected readonly float $h1;
  757. protected readonly float $h2;
  758. readonly float $z1;
  759. readonly float $z2;
  760. readonly float $z3;
  761. }',
  762. '<?php
  763. class Foo
  764. {
  765. readonly int $a, $b;
  766. public readonly int $c, $d;
  767. readonly private string /*1*/$e,/*2*/$f;
  768. readonly float $g;
  769. protected readonly float $h1, $h2;
  770. readonly float $z1, $z2, $z3;
  771. }',
  772. ];
  773. yield [
  774. '<?php
  775. class Foo
  776. {
  777. final public const B1 = "2";
  778. final public const B2 = "2";
  779. readonly float $z2;
  780. }
  781. ',
  782. ];
  783. yield [
  784. '<?php
  785. class Foo
  786. {
  787. private Foo&Bar $prop1;
  788. private Foo&Bar $prop2;
  789. }
  790. ',
  791. '<?php
  792. class Foo
  793. {
  794. private Foo&Bar $prop1, $prop2;
  795. }
  796. ',
  797. ];
  798. yield [
  799. "<?php
  800. enum Foo: string {
  801. public const A = 'A';
  802. public const B = 'B';
  803. case Hearts = 'H';
  804. case Spades = 'S';
  805. }
  806. var_dump(Foo::A.Foo::B);",
  807. "<?php
  808. enum Foo: string {
  809. public const A = 'A', B = 'B';
  810. case Hearts = 'H';
  811. case Spades = 'S';
  812. }
  813. var_dump(Foo::A.Foo::B);",
  814. ];
  815. }
  816. /**
  817. * @dataProvider provideFix82Cases
  818. *
  819. * @requires PHP 8.2
  820. */
  821. public function testFix82(string $expected, ?string $input = null): void
  822. {
  823. $this->doTest($expected, $input);
  824. }
  825. public static function provideFix82Cases(): iterable
  826. {
  827. yield [
  828. '<?php trait Foo { public const Bar = 1; public const Baz = 1; }',
  829. '<?php trait Foo { public const Bar = 1, Baz = 1; }',
  830. ];
  831. }
  832. }