RuleSetDocumentationGeneratorTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\RuleSetDocumentationGenerator;
  15. use PhpCsFixer\FixerFactory;
  16. use PhpCsFixer\RuleSet\RuleSets;
  17. use PhpCsFixer\RuleSet\Sets\PERSet;
  18. use PhpCsFixer\RuleSet\Sets\SymfonySet;
  19. use PhpCsFixer\Tests\TestCase;
  20. /**
  21. * @internal
  22. *
  23. * @covers \PhpCsFixer\Documentation\RuleSetDocumentationGenerator
  24. */
  25. final class RuleSetDocumentationGeneratorTest extends TestCase
  26. {
  27. /**
  28. * @dataProvider provideGenerateRuleSetsDocumentationCases
  29. */
  30. public function testGenerateRuleSetsDocumentation(string $ruleSetName): void
  31. {
  32. $locator = new DocumentationLocator();
  33. $generator = new RuleSetDocumentationGenerator($locator);
  34. $fixerFactory = new FixerFactory();
  35. $fixerFactory->registerBuiltInFixers();
  36. $fixers = $fixerFactory->getFixers();
  37. self::assertSame(
  38. file_get_contents($locator->getRuleSetsDocumentationFilePath($ruleSetName)),
  39. $generator->generateRuleSetsDocumentation(RuleSets::getSetDefinition($ruleSetName), $fixers),
  40. );
  41. }
  42. /**
  43. * @return iterable<array{string}>
  44. */
  45. public static function provideGenerateRuleSetsDocumentationCases(): iterable
  46. {
  47. yield ['@PER'];
  48. yield ['@PhpCsFixer:risky'];
  49. }
  50. public function testGenerateRuleSetsDocumentationIndex(): void
  51. {
  52. $locator = new DocumentationLocator();
  53. $generator = new RuleSetDocumentationGenerator($locator);
  54. self::assertSame(
  55. <<<'RST'
  56. ===========================
  57. List of Available Rule sets
  58. ===========================
  59. - `@PER <./PER.rst>`_ *(deprecated)*
  60. - `@Symfony <./Symfony.rst>`_
  61. RST,
  62. $generator->generateRuleSetsDocumentationIndex([
  63. $locator->getRuleSetsDocumentationFilePath('@PER') => new PERSet(),
  64. $locator->getRuleSetsDocumentationFilePath('@Symfony') => new SymfonySet(),
  65. ]),
  66. );
  67. }
  68. }