123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <?php
- /*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- * Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace PhpCsFixer\Tests\Report;
- use PhpCsFixer\Report\ReporterInterface;
- use PhpCsFixer\Report\ReportSummary;
- use PHPUnit\Framework\TestCase;
- /**
- * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * @internal
- */
- abstract class AbstractReporterTestCase extends TestCase
- {
- /**
- * @var ReporterInterface
- */
- protected $reporter;
- protected function setUp()
- {
- $this->reporter = $this->createReporter();
- }
- final public function testGetFormat()
- {
- $this->assertSame(
- $this->getFormat(),
- $this->reporter->getFormat()
- );
- }
- /**
- * @param string $expectedReport
- * @param ReportSummary $reportSummary
- *
- * @dataProvider provideGenerateCases
- */
- final public function testGenerate($expectedReport, ReportSummary $reportSummary)
- {
- $actualReport = $this->reporter->generate($reportSummary);
- $this->assertFormat($expectedReport, $actualReport);
- }
- /**
- * @return array
- */
- final public function provideGenerateCases()
- {
- return array(
- 'no errors' => array(
- $this->createNoErrorReport(),
- new ReportSummary(
- array(),
- 0,
- 0,
- false,
- false,
- false
- ),
- ),
- 'simple' => array(
- $this->createSimpleReport(),
- new ReportSummary(
- array(
- 'someFile.php' => array(
- 'appliedFixers' => array('some_fixer_name_here'),
- ),
- ),
- 0,
- 0,
- false,
- false,
- false
- ),
- ),
- 'with diff' => array(
- $this->createWithDiffReport(),
- new ReportSummary(
- array(
- 'someFile.php' => array(
- 'appliedFixers' => array('some_fixer_name_here'),
- 'diff' => 'this text is a diff ;)',
- ),
- ),
- 0,
- 0,
- false,
- false,
- false
- ),
- ),
- 'with applied fixers' => array(
- $this->createWithAppliedFixersReport(),
- new ReportSummary(
- array(
- 'someFile.php' => array(
- 'appliedFixers' => array('some_fixer_name_here_1', 'some_fixer_name_here_2'),
- ),
- ),
- 0,
- 0,
- true,
- false,
- false
- ),
- ),
- 'with time and memory' => array(
- $this->createWithTimeAndMemoryReport(),
- new ReportSummary(
- array(
- 'someFile.php' => array(
- 'appliedFixers' => array('some_fixer_name_here'),
- ),
- ),
- 1234,
- 2.5 * 1024 * 1024,
- false,
- false,
- false
- ),
- ),
- 'complex' => array(
- $this->createComplexReport(),
- new ReportSummary(
- array(
- 'someFile.php' => array(
- 'appliedFixers' => array('some_fixer_name_here_1', 'some_fixer_name_here_2'),
- 'diff' => 'this text is a diff ;)',
- ),
- 'anotherFile.php' => array(
- 'appliedFixers' => array('another_fixer_name_here'),
- 'diff' => 'another diff here ;)',
- ),
- ),
- 1234,
- 2.5 * 1024 * 1024,
- true,
- true,
- true
- ),
- ),
- );
- }
- /**
- * @return ReporterInterface
- */
- abstract protected function createReporter();
- /**
- * @return string
- */
- abstract protected function getFormat();
- /**
- * @return string
- */
- abstract protected function createNoErrorReport();
- /**
- * @return string
- */
- abstract protected function createSimpleReport();
- /**
- * @return string
- */
- abstract protected function createWithDiffReport();
- /**
- * @return string
- */
- abstract protected function createWithAppliedFixersReport();
- /**
- * @return string
- */
- abstract protected function createWithTimeAndMemoryReport();
- /**
- * @return string
- */
- abstract protected function createComplexReport();
- /**
- * @param string $expected
- * @param string $input
- */
- abstract protected function assertFormat($expected, $input);
- }
|