AbstractReporterTestCase.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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\Console\Report\ListSetsReport;
  13. use PhpCsFixer\Console\Report\ListSetsReport\ReporterInterface;
  14. use PhpCsFixer\Console\Report\ListSetsReport\ReportSummary;
  15. use PhpCsFixer\RuleSet\Sets\PhpCsFixerSet;
  16. use PhpCsFixer\RuleSet\Sets\SymfonyRiskySet;
  17. use PhpCsFixer\Tests\TestCase;
  18. /**
  19. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  20. *
  21. * @internal
  22. */
  23. abstract class AbstractReporterTestCase extends TestCase
  24. {
  25. protected ?ReporterInterface $reporter = null;
  26. protected function setUp(): void
  27. {
  28. parent::setUp();
  29. $this->reporter = $this->createReporter();
  30. }
  31. protected function tearDown(): void
  32. {
  33. parent::tearDown();
  34. $this->reporter = null;
  35. }
  36. final public function testGetFormat(): void
  37. {
  38. self::assertSame(
  39. $this->getFormat(),
  40. $this->reporter->getFormat()
  41. );
  42. }
  43. /**
  44. * @dataProvider provideGenerateCases
  45. */
  46. final public function testGenerate(string $expectedReport, ReportSummary $reportSummary): void
  47. {
  48. $actualReport = $this->reporter->generate($reportSummary);
  49. $this->assertFormat($expectedReport, $actualReport);
  50. }
  51. /**
  52. * @return iterable<string, array{string, ReportSummary}>
  53. */
  54. final public static function provideGenerateCases(): iterable
  55. {
  56. yield 'example' => [
  57. static::createSimpleReport(),
  58. new ReportSummary([
  59. new SymfonyRiskySet(),
  60. new PhpCsFixerSet(),
  61. ]),
  62. ];
  63. }
  64. abstract protected function createReporter(): ReporterInterface;
  65. abstract protected function getFormat(): string;
  66. abstract protected function assertFormat(string $expected, string $input): void;
  67. abstract protected static function createSimpleReport(): string;
  68. }