HeaderCommentFixerTest.php 19 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  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\Comment;
  13. use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
  14. use PhpCsFixer\ConfigurationException\RequiredFixerConfigurationException;
  15. use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
  16. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  17. use PhpCsFixer\WhitespacesFixerConfig;
  18. /**
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Fixer\Comment\HeaderCommentFixer
  22. *
  23. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Comment\HeaderCommentFixer>
  24. *
  25. * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\Comment\HeaderCommentFixer
  26. */
  27. final class HeaderCommentFixerTest extends AbstractFixerTestCase
  28. {
  29. /**
  30. * @param _AutogeneratedInputConfiguration $configuration
  31. *
  32. * @dataProvider provideFixCases
  33. */
  34. public function testFix(array $configuration, string $expected, ?string $input = null): void
  35. {
  36. $this->fixer->configure($configuration);
  37. $this->doTest($expected, $input);
  38. }
  39. public static function provideFixCases(): iterable
  40. {
  41. yield [
  42. ['header' => ''],
  43. '<?php
  44. $a;',
  45. '<?php
  46. /**
  47. * new
  48. */
  49. $a;',
  50. ];
  51. yield [
  52. [
  53. 'header' => 'tmp',
  54. 'location' => 'after_declare_strict',
  55. ],
  56. '<?php
  57. declare(strict_types=1);
  58. /*
  59. * tmp
  60. */
  61. namespace A\B;
  62. echo 1;',
  63. '<?php
  64. declare(strict_types=1);namespace A\B;
  65. echo 1;',
  66. ];
  67. yield [
  68. [
  69. 'header' => 'tmp',
  70. 'location' => 'after_declare_strict',
  71. 'separate' => 'bottom',
  72. 'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
  73. ],
  74. '<?php
  75. declare(strict_types=1);
  76. /**
  77. * tmp
  78. */
  79. namespace A\B;
  80. echo 1;',
  81. '<?php
  82. declare(strict_types=1);
  83. namespace A\B;
  84. echo 1;',
  85. ];
  86. yield [
  87. [
  88. 'header' => 'tmp',
  89. 'location' => 'after_open',
  90. ],
  91. '<?php
  92. /*
  93. * tmp
  94. */
  95. declare(strict_types=1);
  96. namespace A\B;
  97. echo 1;',
  98. '<?php
  99. declare(strict_types=1);
  100. namespace A\B;
  101. echo 1;',
  102. ];
  103. yield [
  104. [
  105. 'header' => 'new',
  106. 'comment_type' => HeaderCommentFixer::HEADER_COMMENT,
  107. ],
  108. '<?php
  109. /*
  110. * new
  111. */
  112. ',
  113. '<?php
  114. /** test */
  115. ',
  116. ];
  117. yield [
  118. [
  119. 'header' => 'new',
  120. 'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
  121. ],
  122. '<?php
  123. /**
  124. * new
  125. */
  126. ',
  127. '<?php
  128. /* test */
  129. ',
  130. ];
  131. yield [
  132. [
  133. 'header' => 'def',
  134. 'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
  135. ],
  136. '<?php
  137. /**
  138. * def
  139. */
  140. ',
  141. '<?php
  142. ',
  143. ];
  144. yield [
  145. ['header' => 'xyz'],
  146. '<?php
  147. /*
  148. * xyz
  149. */
  150. $b;',
  151. '<?php
  152. $b;',
  153. ];
  154. yield [
  155. [
  156. 'header' => 'xyz123',
  157. 'separate' => 'none',
  158. ],
  159. '<?php
  160. /*
  161. * xyz123
  162. */
  163. $a;',
  164. '<?php
  165. $a;',
  166. ];
  167. yield [
  168. [
  169. 'header' => 'abc',
  170. 'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
  171. ],
  172. '<?php
  173. /**
  174. * abc
  175. */
  176. $c;',
  177. '<?php
  178. $c;',
  179. ];
  180. yield [
  181. [
  182. 'header' => 'ghi',
  183. 'separate' => 'both',
  184. ],
  185. '<?php
  186. /*
  187. * ghi
  188. */
  189. $d;',
  190. '<?php
  191. $d;',
  192. ];
  193. yield [
  194. [
  195. 'header' => 'ghi',
  196. 'separate' => 'top',
  197. ],
  198. '<?php
  199. /*
  200. * ghi
  201. */
  202. $d;',
  203. '<?php
  204. $d;',
  205. ];
  206. yield [
  207. [
  208. 'header' => 'tmp',
  209. 'location' => 'after_declare_strict',
  210. ],
  211. '<?php
  212. /*
  213. * tmp
  214. */
  215. declare(ticks=1);
  216. echo 1;',
  217. '<?php
  218. declare(ticks=1);
  219. echo 1;',
  220. ];
  221. yield [
  222. ['header' => 'Foo'],
  223. '<?php
  224. /*
  225. * Foo
  226. */
  227. echo \'bar\';',
  228. '<?php echo \'bar\';',
  229. ];
  230. yield [
  231. ['header' => 'x'],
  232. '<?php
  233. /*
  234. * x
  235. */
  236. echo \'a\';',
  237. '<?php
  238. /*
  239. * y
  240. * z
  241. */
  242. echo \'a\';',
  243. ];
  244. yield [
  245. ['header' => "a\na"],
  246. '<?php
  247. /*
  248. * a
  249. * a
  250. */
  251. echo \'x\';',
  252. '<?php
  253. /*
  254. * b
  255. * c
  256. */
  257. echo \'x\';',
  258. ];
  259. yield [
  260. [
  261. 'header' => 'foo',
  262. 'location' => 'after_open',
  263. 'separate' => 'bottom',
  264. 'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
  265. ],
  266. '<?php
  267. /**
  268. * foo
  269. */
  270. declare(strict_types=1);
  271. namespace A;
  272. echo 1;',
  273. '<?php
  274. declare(strict_types=1);
  275. /**
  276. * foo
  277. */
  278. namespace A;
  279. echo 1;',
  280. ];
  281. yield [
  282. [
  283. 'header' => 'foo',
  284. 'location' => 'after_open',
  285. 'separate' => 'bottom',
  286. 'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
  287. ],
  288. '<?php
  289. /**
  290. * foo
  291. */
  292. declare(strict_types=1);
  293. /**
  294. * bar
  295. */
  296. namespace A;
  297. echo 1;',
  298. '<?php
  299. declare(strict_types=1);
  300. /**
  301. * bar
  302. */
  303. namespace A;
  304. echo 1;',
  305. ];
  306. yield [
  307. [
  308. 'header' => 'Foo',
  309. 'separate' => 'none',
  310. ],
  311. '<?php
  312. declare(strict_types=1);
  313. /*
  314. * Foo
  315. */
  316. namespace SebastianBergmann\Foo;
  317. class Bar
  318. {
  319. }',
  320. '<?php
  321. /*
  322. * Foo
  323. */
  324. declare(strict_types=1);
  325. namespace SebastianBergmann\Foo;
  326. class Bar
  327. {
  328. }',
  329. ];
  330. yield [
  331. ['header' => 'tmp'],
  332. '<?php
  333. /*
  334. * tmp
  335. */
  336. /**
  337. * Foo class doc.
  338. */
  339. class Foo {}',
  340. '<?php
  341. /**
  342. * Foo class doc.
  343. */
  344. class Foo {}',
  345. ];
  346. yield [
  347. ['header' => 'tmp'],
  348. '<?php
  349. /*
  350. * tmp
  351. */
  352. class Foo {}',
  353. '<?php
  354. /*
  355. * Foo class doc.
  356. */
  357. class Foo {}',
  358. ];
  359. yield [
  360. [
  361. 'header' => 'tmp1',
  362. 'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
  363. ],
  364. '<?php
  365. /**
  366. * tmp1
  367. */
  368. /**
  369. * Foo class doc.
  370. */
  371. class Foo {}',
  372. '<?php
  373. /**
  374. * Foo class doc.
  375. */
  376. class Foo {}',
  377. ];
  378. yield [
  379. [
  380. 'header' => 'tmp2',
  381. 'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
  382. ],
  383. '<?php
  384. /**
  385. * tmp2
  386. */
  387. class Foo {}',
  388. '<?php
  389. /**
  390. * tmp2
  391. */
  392. class Foo {}',
  393. ];
  394. yield [
  395. [
  396. 'header' => 'tmp3',
  397. 'separate' => 'top',
  398. ],
  399. '<?php
  400. /*
  401. * tmp3
  402. */
  403. class Foo {}',
  404. '<?php
  405. /**
  406. * Foo class doc.
  407. */
  408. class Foo {}',
  409. ];
  410. yield [
  411. [
  412. 'header' => 'bar',
  413. 'location' => 'after_open',
  414. ],
  415. '<?php
  416. /*
  417. * bar
  418. */
  419. declare(strict_types=1);
  420. // foo
  421. foo();',
  422. '<?php
  423. /*
  424. * foo
  425. */
  426. declare(strict_types=1);
  427. // foo
  428. foo();',
  429. ];
  430. yield [
  431. [
  432. 'header' => 'bar',
  433. 'location' => 'after_open',
  434. ],
  435. '<?php
  436. /*
  437. * bar
  438. */
  439. declare(strict_types=1);
  440. /* foo */
  441. foo();',
  442. '<?php
  443. /*
  444. * foo
  445. */
  446. declare(strict_types=1);
  447. /* foo */
  448. foo();',
  449. ];
  450. yield [
  451. [
  452. 'header' => 'tmp4',
  453. 'location' => 'after_declare_strict',
  454. ],
  455. '<?php
  456. /*
  457. * tmp4
  458. */
  459. declare(strict_types=1) ?>',
  460. '<?php
  461. declare(strict_types=1) ?>',
  462. ];
  463. yield [
  464. [
  465. 'header' => 'tmp5',
  466. 'location' => 'after_declare_strict',
  467. ],
  468. '#!/usr/bin/env php
  469. <?php
  470. declare(strict_types=1);
  471. /*
  472. * tmp5
  473. */
  474. namespace A\B;
  475. echo 1;',
  476. '#!/usr/bin/env php
  477. <?php
  478. declare(strict_types=1);namespace A\B;
  479. echo 1;',
  480. ];
  481. yield [
  482. [
  483. 'header' => 'tmp',
  484. 'location' => 'after_open',
  485. ],
  486. 'Short mixed file A
  487. Hello<?php echo "World!"; ?>',
  488. ];
  489. yield [
  490. [
  491. 'header' => 'tmp',
  492. 'location' => 'after_open',
  493. ],
  494. 'Short mixed file B
  495. <?php echo "Hello"; ?>World!',
  496. ];
  497. yield [
  498. [
  499. 'header' => 'tmp',
  500. 'location' => 'after_open',
  501. ],
  502. 'File with anything at the beginning and with multiple opening tags are not supported
  503. <?php
  504. echo 1;
  505. ?>Hello World!<?php
  506. script_continues_here();',
  507. ];
  508. $fileHeaderParts = [
  509. <<<'EOF'
  510. This file is part of the xxx.
  511. (c) Foo Bar <foo@bar.com>
  512. EOF,
  513. <<<'EOF'
  514. For the full copyright and license information, please view the LICENSE
  515. file that was distributed with this source code.
  516. EOF,
  517. ];
  518. $fileHeaderComment = implode('', $fileHeaderParts);
  519. $fileHeaderCommentValidator = implode('', [
  520. '/',
  521. preg_quote($fileHeaderParts[0], '/'),
  522. '(?P<EXTRA>.*)??',
  523. preg_quote($fileHeaderParts[1], '/'),
  524. '/s',
  525. ]);
  526. yield 'using validator, but existing comment in wrong place - adding new one' => [
  527. [
  528. 'header' => $fileHeaderComment,
  529. 'validator' => $fileHeaderCommentValidator,
  530. 'location' => 'after_open',
  531. ],
  532. '<?php
  533. /*
  534. * This file is part of the xxx.
  535. *
  536. * (c) Foo Bar <foo@bar.com>
  537. *
  538. * This
  539. * is
  540. * sub
  541. * note.
  542. *
  543. * For the full copyright and license information, please view the LICENSE
  544. * file that was distributed with this source code.
  545. */
  546. declare(strict_types=1);
  547. namespace A;
  548. echo 1;',
  549. '<?php
  550. declare(strict_types=1);
  551. /*
  552. * This file is part of the xxx.
  553. *
  554. * (c) Foo Bar <foo@bar.com>
  555. *
  556. * This
  557. * is
  558. * sub
  559. * note.
  560. *
  561. * For the full copyright and license information, please view the LICENSE
  562. * file that was distributed with this source code.
  563. */
  564. namespace A;
  565. echo 1;',
  566. ];
  567. yield 'using validator, existing comment matches' => [
  568. [
  569. 'header' => $fileHeaderComment,
  570. 'validator' => $fileHeaderCommentValidator,
  571. 'location' => 'after_open',
  572. ],
  573. '<?php
  574. /*
  575. * This file is part of the xxx.
  576. *
  577. * (c) Foo Bar <foo@bar.com>
  578. *
  579. * This
  580. * is
  581. * sub
  582. * note.
  583. *
  584. * For the full copyright and license information, please view the LICENSE
  585. * file that was distributed with this source code.
  586. */
  587. declare(strict_types=1);
  588. namespace A;
  589. echo 1;',
  590. ];
  591. yield 'using validator, existing comment matches but misplaced' => [
  592. [
  593. 'header' => $fileHeaderComment,
  594. 'validator' => $fileHeaderCommentValidator,
  595. 'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
  596. ],
  597. '<?php
  598. /**
  599. * This file is part of the xxx.
  600. *
  601. * (c) Foo Bar <foo@bar.com>
  602. *
  603. * This
  604. * is
  605. * sub
  606. * note.
  607. *
  608. * For the full copyright and license information, please view the LICENSE
  609. * file that was distributed with this source code.
  610. */
  611. class Foo {}',
  612. '<?php
  613. /**
  614. * This file is part of the xxx.
  615. *
  616. * (c) Foo Bar <foo@bar.com>
  617. *
  618. * This
  619. * is
  620. * sub
  621. * note.
  622. *
  623. * For the full copyright and license information, please view the LICENSE
  624. * file that was distributed with this source code.
  625. */
  626. class Foo {}',
  627. ];
  628. }
  629. public function testDefaultConfiguration(): void
  630. {
  631. $this->fixer->configure(['header' => 'a']);
  632. $this->doTest(
  633. '<?php
  634. /*
  635. * a
  636. */
  637. echo 1;',
  638. '<?php
  639. echo 1;'
  640. );
  641. }
  642. /**
  643. * @param _AutogeneratedInputConfiguration $configuration
  644. *
  645. * @dataProvider provideMisconfigurationCases
  646. */
  647. public function testMisconfiguration(?array $configuration, string $exceptionMessage): void
  648. {
  649. $this->expectException(InvalidFixerConfigurationException::class);
  650. $this->expectExceptionMessageMatches("#^\\[header_comment\\] {$exceptionMessage}$#");
  651. $this->fixer->configure($configuration);
  652. }
  653. public static function provideMisconfigurationCases(): iterable
  654. {
  655. yield [[], 'Missing required configuration: The required option "header" is missing.'];
  656. yield [
  657. ['header' => 1],
  658. 'Invalid configuration: The option "header" with value 1 is expected to be of type "string", but is of type "(int|integer)"\.',
  659. ];
  660. yield [
  661. [
  662. 'header' => '',
  663. 'comment_type' => 'foo',
  664. ],
  665. 'Invalid configuration: The option "comment_type" with value "foo" is invalid\. Accepted values are: "PHPDoc", "comment"\.',
  666. ];
  667. yield [
  668. [
  669. 'header' => '',
  670. 'comment_type' => new \stdClass(),
  671. ],
  672. 'Invalid configuration: The option "comment_type" with value stdClass is invalid\. Accepted values are: "PHPDoc", "comment"\.',
  673. ];
  674. yield [
  675. [
  676. 'header' => '',
  677. 'location' => new \stdClass(),
  678. ],
  679. 'Invalid configuration: The option "location" with value stdClass is invalid\. Accepted values are: "after_open", "after_declare_strict"\.',
  680. ];
  681. yield [
  682. [
  683. 'header' => '',
  684. 'separate' => new \stdClass(),
  685. ],
  686. 'Invalid configuration: The option "separate" with value stdClass is invalid\. Accepted values are: "both", "top", "bottom", "none"\.',
  687. ];
  688. yield [
  689. [
  690. 'header' => 'Foo',
  691. 'validator' => '/\w+++/',
  692. ],
  693. 'Provided RegEx is not valid.',
  694. ];
  695. }
  696. /**
  697. * @dataProvider provideHeaderGenerationCases
  698. *
  699. * @param HeaderCommentFixer::HEADER_* $type
  700. */
  701. public function testHeaderGeneration(string $expected, string $header, string $type): void
  702. {
  703. $this->fixer->configure([
  704. 'header' => $header,
  705. 'comment_type' => $type,
  706. ]);
  707. $this->doTest(
  708. '<?php
  709. '.$expected.'
  710. echo 1;',
  711. '<?php
  712. echo 1;'
  713. );
  714. }
  715. /**
  716. * @return iterable<array{string, string, string}>
  717. */
  718. public static function provideHeaderGenerationCases(): iterable
  719. {
  720. yield [
  721. '/*
  722. * a
  723. */',
  724. 'a',
  725. HeaderCommentFixer::HEADER_COMMENT,
  726. ];
  727. yield [
  728. '/**
  729. * a
  730. */',
  731. 'a',
  732. HeaderCommentFixer::HEADER_PHPDOC,
  733. ];
  734. }
  735. /**
  736. * @dataProvider provideDoNotTouchCases
  737. */
  738. public function testDoNotTouch(string $expected): void
  739. {
  740. $this->fixer->configure([
  741. 'header' => '',
  742. ]);
  743. $this->doTest($expected);
  744. }
  745. /**
  746. * @return iterable<array{string}>
  747. */
  748. public static function provideDoNotTouchCases(): iterable
  749. {
  750. yield ["<?php\nphpinfo();\n?>\n<?"];
  751. yield [" <?php\nphpinfo();\n"];
  752. yield ["<?php\nphpinfo();\n?><hr/>"];
  753. yield [" <?php\n"];
  754. yield ['<?= 1?>'];
  755. yield ["<?= 1?><?php\n"];
  756. yield ["<?= 1?>\n<?php\n"];
  757. yield ["<?php\n// comment 1\n?><?php\n// comment 2\n"];
  758. }
  759. public function testWithoutConfiguration(): void
  760. {
  761. $this->expectException(RequiredFixerConfigurationException::class);
  762. $this->doTest('<?php echo 1;');
  763. }
  764. /**
  765. * @param _AutogeneratedInputConfiguration $configuration
  766. *
  767. * @dataProvider provideMessyWhitespacesCases
  768. */
  769. public function testMessyWhitespaces(array $configuration, string $expected, ?string $input = null): void
  770. {
  771. $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n"));
  772. $this->fixer->configure($configuration);
  773. $this->doTest($expected, $input);
  774. }
  775. public static function provideMessyWhitespacesCases(): iterable
  776. {
  777. yield [
  778. [
  779. 'header' => 'whitemess',
  780. 'location' => 'after_declare_strict',
  781. 'separate' => 'bottom',
  782. 'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
  783. ],
  784. "<?php\r\ndeclare(strict_types=1);\r\n/**\r\n * whitemess\r\n */\r\n\r\nnamespace A\\B;\r\n\r\necho 1;",
  785. "<?php\r\ndeclare(strict_types=1);\r\n\r\nnamespace A\\B;\r\n\r\necho 1;",
  786. ];
  787. }
  788. public function testConfigurationUpdatedWithWhitespsacesConfig(): void
  789. {
  790. $this->fixer->configure(['header' => 'Foo']);
  791. $this->doTest(
  792. "<?php\n\n/*\n * Foo\n */\n\necho 1;",
  793. "<?php\necho 1;"
  794. );
  795. $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig(' ', "\r\n"));
  796. $this->doTest(
  797. "<?php\r\n\r\n/*\r\n * Foo\r\n */\r\n\r\necho 1;",
  798. "<?php\r\necho 1;"
  799. );
  800. $this->fixer->configure(['header' => 'Bar']);
  801. $this->doTest(
  802. "<?php\r\n\r\n/*\r\n * Bar\r\n */\r\n\r\necho 1;",
  803. "<?php\r\necho 1;"
  804. );
  805. $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig(' ', "\n"));
  806. $this->doTest(
  807. "<?php\n\n/*\n * Bar\n */\n\necho 1;",
  808. "<?php\necho 1;"
  809. );
  810. }
  811. public function testInvalidHeaderConfiguration(): void
  812. {
  813. $this->expectException(InvalidFixerConfigurationException::class);
  814. $this->expectExceptionMessageMatches('#^\[header_comment\] Cannot use \'\*/\' in header\.$#');
  815. $this->fixer->configure([
  816. 'header' => '/** test */',
  817. 'comment_type' => HeaderCommentFixer::HEADER_PHPDOC,
  818. ]);
  819. }
  820. /**
  821. * @param _AutogeneratedInputConfiguration $configuration
  822. *
  823. * @dataProvider provideFix81Cases
  824. *
  825. * @requires PHP 8.1
  826. */
  827. public function testFix81(array $configuration, string $expected, ?string $input = null): void
  828. {
  829. $this->fixer->configure($configuration);
  830. $this->doTest($expected, $input);
  831. }
  832. public static function provideFix81Cases(): iterable
  833. {
  834. yield [
  835. ['header' => 'tmp'],
  836. '<?php
  837. /*
  838. * tmp
  839. */
  840. /**
  841. * Foo class doc.
  842. */
  843. enum Foo {}',
  844. '<?php
  845. /**
  846. * Foo class doc.
  847. */
  848. enum Foo {}',
  849. ];
  850. }
  851. }