AbstractReporterTestCase.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. /**
  26. * @var null|ReporterInterface
  27. */
  28. protected $reporter;
  29. protected function setUp(): void
  30. {
  31. parent::setUp();
  32. $this->reporter = $this->createReporter();
  33. }
  34. protected function tearDown(): void
  35. {
  36. parent::tearDown();
  37. $this->reporter = null;
  38. }
  39. final public function testGetFormat(): void
  40. {
  41. self::assertSame(
  42. $this->getFormat(),
  43. $this->reporter->getFormat()
  44. );
  45. }
  46. /**
  47. * @dataProvider provideGenerateCases
  48. */
  49. final public function testGenerate(string $expectedReport, ReportSummary $reportSummary): void
  50. {
  51. $actualReport = $this->reporter->generate($reportSummary);
  52. $this->assertFormat($expectedReport, $actualReport);
  53. }
  54. /**
  55. * @return iterable<string, array{string, ReportSummary}>
  56. */
  57. final public static function provideGenerateCases(): iterable
  58. {
  59. yield 'example' => [
  60. static::createSimpleReport(),
  61. new ReportSummary([
  62. new SymfonyRiskySet(),
  63. new PhpCsFixerSet(),
  64. ]),
  65. ];
  66. }
  67. abstract protected function createReporter(): ReporterInterface;
  68. abstract protected function getFormat(): string;
  69. abstract protected function assertFormat(string $expected, string $input): void;
  70. abstract protected static function createSimpleReport(): string;
  71. }