FixerDocumentGeneratorTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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\Documentation;
  13. use PhpCsFixer\Documentation\DocumentationLocator;
  14. use PhpCsFixer\Documentation\FixerDocumentGenerator;
  15. use PhpCsFixer\Fixer\Basic\BracesFixer;
  16. use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer;
  17. use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
  18. use PhpCsFixer\Fixer\FixerInterface;
  19. use PhpCsFixer\Fixer\LanguageConstruct\ClassKeywordFixer;
  20. use PhpCsFixer\Fixer\Strict\StrictParamFixer;
  21. use PhpCsFixer\FixerFactory;
  22. use PhpCsFixer\Tests\TestCase;
  23. /**
  24. * @internal
  25. *
  26. * @covers \PhpCsFixer\Documentation\FixerDocumentGenerator
  27. */
  28. final class FixerDocumentGeneratorTest extends TestCase
  29. {
  30. /**
  31. * @dataProvider provideGenerateRuleSetsDocumentationCases
  32. */
  33. public function testGenerateRuleSetsDocumentation(FixerInterface $fixer): void
  34. {
  35. $locator = new DocumentationLocator();
  36. $generator = new FixerDocumentGenerator($locator);
  37. self::assertSame(
  38. file_get_contents($locator->getFixerDocumentationFilePath($fixer)),
  39. $generator->generateFixerDocumentation($fixer),
  40. );
  41. }
  42. /**
  43. * @return iterable<array{FixerInterface}>
  44. */
  45. public static function provideGenerateRuleSetsDocumentationCases(): iterable
  46. {
  47. yield [new BracesFixer()];
  48. yield [new ClassKeywordFixer()];
  49. yield [new HeaderCommentFixer()];
  50. yield [new StrictParamFixer()];
  51. yield [new VisibilityRequiredFixer()];
  52. }
  53. public function testGenerateFixersDocumentationIndex(): void
  54. {
  55. $locator = new DocumentationLocator();
  56. $generator = new FixerDocumentGenerator($locator);
  57. $fixerFactory = new FixerFactory();
  58. $fixerFactory->registerBuiltInFixers();
  59. $fixers = $fixerFactory->getFixers();
  60. self::assertSame(
  61. file_get_contents($locator->getFixersDocumentationIndexFilePath()),
  62. $generator->generateFixersDocumentationIndex($fixers),
  63. );
  64. }
  65. }